Skip to main content

RequestBuilderExt

Trait RequestBuilderExt 

Source
pub trait RequestBuilderExt: Sized + Sealed {
    // Required methods
    fn typed_header<T>(self, header: T) -> Self
       where T: Header;
    fn json<T: Serialize + ?Sized>(
        self,
        value: &T,
    ) -> Result<Request<Bytes>, SetBodyError<Error>>;
    fn form<T: Serialize + ?Sized>(
        self,
        form: &T,
    ) -> Result<Request<Bytes>, SetBodyError<Error>>;
    fn query<T: Serialize + ?Sized>(self, query: &T) -> Result<Self, Error>;
}
Expand description

Extension trait for the http::request::Builder.

Required Methods§

Source

fn typed_header<T>(self, header: T) -> Self
where T: Header,

Available on crate feature typed-header only.

Appends a typed header to this request.

This function will append the provided header as a header to the internal http::HeaderMap being constructed. Essentially this is equivalent to calling headers::HeaderMapExt::typed_insert.

Source

fn json<T: Serialize + ?Sized>( self, value: &T, ) -> Result<Request<Bytes>, SetBodyError<Error>>

Available on crate feature json only.

Sets a JSON body for this request.

Additionally this method adds a CONTENT_TYPE header for JSON body. If you decide to override the request body, keep this in mind.

§Errors

If the given value’s implementation of serde::Serialize decides to fail.

Source

fn form<T: Serialize + ?Sized>( self, form: &T, ) -> Result<Request<Bytes>, SetBodyError<Error>>

Available on crate feature form only.

Sets a form body for this request.

Additionally this method adds a CONTENT_TYPE header for form body. If you decide to override the request body, keep this in mind.

§Errors

If the given value’s implementation of serde::Serialize decides to fail.

Source

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

Available on crate feature query only.

Sets the query string of the URL.

Serializes the given value into a query string using serde_urlencoded and replaces the existing query string of the URL entirely. Any previously set query parameters are discarded.

§Notes
  • Duplicate keys are preserved as-is: .query(&[("foo", "a"), ("foo", "b")]) produces "foo=a&foo=b".

  • This method does not support a single key-value tuple directly. Use a slice like .query(&[("key", "val")]) instead. Structs and maps that serialize into key-value pairs are also supported.

§Errors

Returns a serde_urlencoded::ser::Error if the provided value cannot be serialized into a query string.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl RequestBuilderExt for Builder

Source§

fn typed_header<T>(self, header: T) -> Self
where T: Header,

Available on crate feature typed-header only.
Source§

fn json<T: Serialize + ?Sized>( self, value: &T, ) -> Result<Request<Bytes>, SetBodyError<Error>>

Available on crate feature json only.
Source§

fn form<T: Serialize + ?Sized>( self, form: &T, ) -> Result<Request<Bytes>, SetBodyError<Error>>

Available on crate feature form only.
Source§

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

Available on crate feature query only.

Implementors§