pub struct Client;Expand description
Main client for making HTTP requests
Implementations§
Source§impl Client
impl Client
Sourcepub fn get(&self, url: impl Into<String>) -> RequestBuilder
pub fn get(&self, url: impl Into<String>) -> RequestBuilder
Make a GET request
Examples found in repository?
examples/github_api.rs (line 34)
29async fn get_github_branch_advanced(repo: String) -> Result<GitHubBranch> {
30 let client = Client;
31 let url = format!("https://api.github.com/repos/{}/branches/master", repo);
32
33 let response = client
34 .get(url)
35 .header("Accept", "application/vnd.github.v3+json")
36 .header("User-Agent", "rust-wasm-fetch")
37 .send()
38 .await?
39 .error_for_status()?;
40
41 response.json().await
42}Sourcepub fn post(&self, url: impl Into<String>) -> RequestBuilder
pub fn post(&self, url: impl Into<String>) -> RequestBuilder
Make a POST request
Examples found in repository?
examples/github_api.rs (line 58)
51async fn create_github_issue(repo: String, title: String, body: String) -> Result<Value> {
52 let client = Client;
53 let url = format!("https://api.github.com/repos/{}/issues", repo);
54
55 let issue = CreateIssue { title, body };
56
57 let response = client
58 .post(url)
59 .header("Accept", "application/vnd.github.v3+json")
60 .header("Authorization", "token YOUR_GITHUB_TOKEN")
61 .json(&issue)?
62 .send()
63 .await?
64 .error_for_status()?;
65
66 response.json_value().await
67}Sourcepub fn put(&self, url: impl Into<String>) -> RequestBuilder
pub fn put(&self, url: impl Into<String>) -> RequestBuilder
Make a PUT request
Sourcepub fn delete(&self, url: impl Into<String>) -> RequestBuilder
pub fn delete(&self, url: impl Into<String>) -> RequestBuilder
Make a DELETE request
Sourcepub fn patch(&self, url: impl Into<String>) -> RequestBuilder
pub fn patch(&self, url: impl Into<String>) -> RequestBuilder
Make a PATCH request
Sourcepub fn head(&self, url: impl Into<String>) -> RequestBuilder
pub fn head(&self, url: impl Into<String>) -> RequestBuilder
Make a HEAD request
Auto Trait Implementations§
impl Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more