Struct Client

Source
pub struct Client;
Expand description

Main client for making HTTP requests

Implementations§

Source§

impl Client

Source

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}
Source

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}
Source

pub fn put(&self, url: impl Into<String>) -> RequestBuilder

Make a PUT request

Source

pub fn delete(&self, url: impl Into<String>) -> RequestBuilder

Make a DELETE request

Source

pub fn patch(&self, url: impl Into<String>) -> RequestBuilder

Make a PATCH 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.