Struct RequestBuilder

Source
pub struct RequestBuilder { /* private fields */ }

Implementations§

Source§

impl RequestBuilder

Source

pub fn header<K, V>(self, key: K, value: V) -> Self
where K: Into<FieldKey>, V: Into<FieldValue>,

Add a header to the Request.

let resp = Client::new().get("https://httpbin.org/get")
    .header("Content-Type", "application/json")
    .send()?;
Source

pub fn headers<K, V, I>(self, headers: I) -> Self
where K: Into<FieldKey>, V: Into<FieldValue>, I: IntoIterator<Item = (K, V)>,

Add a set of headers to the Request.

Existing headers will be overwritten.

let resp = Client::new().get("https://httpbin.org/get")
    .headers([("Content-Type", "application/json"), ("Accept", "*/*")])
    .send()?;
Source

pub fn query<T: Serialize + ?Sized>(self, query: &T) -> Self

Modify the query string of the Request URL.

let resp = Client::new().get("https://httpbin.org/get")
    .query(&[("a", "b"), ("c", "d")])
    .send()?;
Source

pub fn body(self, body: &[u8]) -> Self

Set the request body.

let resp = Client::new().post("https://httpbin.org/post")
    .body("hello".as_bytes())
    .send()?;
Source

pub fn json<T: Serialize + ?Sized>(self, json: &T) -> Self

Available on crate feature json only.

Send a JSON body.

§Optional

This requires the json feature enabled.

let resp = Client::new().post("https://httpbin.org/post")
    .json(&HashMap::from([("data", "hello")]))
    .send()?;
Source

pub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self

Send a form body.

let resp = Client::new().post("https://httpbin.org/post")
    .form(&[("a", "b"), ("c", "d")])
    .send()?;
Source

pub fn connect_timeout(self, timeout: Duration) -> Self

Set the timeout for the initial connect to the HTTP Server.

let resp = Client::new().post("https://httpbin.org/post")
    .connect_timeout(Duration::from_secs(5))
    .send()?;
Source

pub fn send(self) -> Result<Response>

Send the Request, returning a Response.

Auto Trait Implementations§

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,