pub struct RequestBuilder { /* private fields */ }Expand description
A request builder bound to a ClientWithMiddleware.
Wraps reqwest::RequestBuilder and adds
RequestBuilder::with_extension for request-scoped typed data that
every middleware can read (extensions.get::<T>() in
Middleware::handle).
Not Clone (reqwest’s builder isn’t either); use
RequestBuilder::try_clone for bufferable requests.
Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn with_extension<T: Clone + Send + Sync + 'static>(self, value: T) -> Self
pub fn with_extension<T: Clone + Send + Sync + 'static>(self, value: T) -> Self
Attach request-scoped typed data, visible to every middleware in
the chain through the extensions argument of
Middleware::handle (extensions.get::<T>()). The map is shared
across retry attempts of the same logical request, so the data
survives retries.
Sourcepub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Add a single header.
Sourcepub fn json<T: Serialize + ?Sized>(self, body: &T) -> Self
pub fn json<T: Serialize + ?Sized>(self, body: &T) -> Self
Set a JSON body (requires the json feature).
Sourcepub fn bearer_auth(self, token: impl Display) -> Self
pub fn bearer_auth(self, token: impl Display) -> Self
Set a Bearer authorization token.
Sourcepub fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Self
pub fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Self
Set HTTP basic auth credentials.
Sourcepub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
pub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
Set form-encoded body from a serializable value.
Sourcepub fn build(self) -> Result<Request>
pub fn build(self) -> Result<Request>
Build the request without sending it.
Extension values registered via RequestBuilder::with_extension
are applied by RequestBuilder::send (they seed the per-request
extension map passed to middleware, which reqwest’s Request type
does not expose).
Sourcepub fn try_clone(&self) -> Option<Self>
pub fn try_clone(&self) -> Option<Self>
Clone the builder, if the underlying request is cloneable (buffered bodies are; streaming bodies are not).
Sourcepub async fn send(self) -> Result<Response>
pub async fn send(self) -> Result<Response>
Build and execute the request through the middleware chain,
seeding the per-request extension map with any
RequestBuilder::with_extension values.