Struct RequestBuilder
pub struct RequestBuilder { /* private fields */ }Expand description
A builder to construct the properties of a Request.
To construct a RequestBuilder, refer to the Client documentation.
Implementations§
§impl RequestBuilder
impl RequestBuilder
pub fn from_parts(client: Client, request: Request) -> RequestBuilder
pub fn from_parts(client: Client, request: Request) -> RequestBuilder
Assemble a builder starting from an existing Client and a Request.
pub fn header<K, V>(self, key: K, value: V) -> RequestBuilderwhere
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) -> RequestBuilderwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Add a Header to this Request.
pub fn headers(self, headers: HeaderMap) -> RequestBuilder
pub fn headers(self, headers: HeaderMap) -> RequestBuilder
Add a set of Headers to the existing ones on this Request.
The headers will be merged in to any already set.
pub fn basic_auth<U, P>(
self,
username: U,
password: Option<P>,
) -> RequestBuilder
pub fn basic_auth<U, P>( self, username: U, password: Option<P>, ) -> RequestBuilder
Enable HTTP basic authentication.
let client = reqwest::Client::new();
let resp = client.delete("http://httpbin.org/delete")
.basic_auth("admin", Some("good password"))
.send()
.await?;pub fn bearer_auth<T>(self, token: T) -> RequestBuilderwhere
T: Display,
pub fn bearer_auth<T>(self, token: T) -> RequestBuilderwhere
T: Display,
Enable HTTP bearer authentication.
pub fn body<T>(self, body: T) -> RequestBuilder
pub fn body<T>(self, body: T) -> RequestBuilder
Set the request body.
pub fn timeout(self, timeout: Duration) -> RequestBuilder
pub fn timeout(self, timeout: Duration) -> RequestBuilder
Enables a request timeout.
The timeout is applied from when the request starts connecting until the
response body has finished. It affects only this request and overrides
the timeout configured using ClientBuilder::timeout().
pub fn version(self, version: Version) -> RequestBuilder
pub fn version(self, version: Version) -> RequestBuilder
Set HTTP version
pub fn form<T>(self, form: &T) -> RequestBuilder
pub fn form<T>(self, form: &T) -> RequestBuilder
Send a form body.
Sets the body to the url encoded serialization of the passed value,
and also sets the Content-Type: application/x-www-form-urlencoded
header.
let mut params = HashMap::new();
params.insert("lang", "rust");
let client = reqwest::Client::new();
let res = client.post("http://httpbin.org")
.form(¶ms)
.send()
.await?;§Optional
This requires the optional form feature to be enabled.
§Errors
This method fails if the passed value cannot be serialized into url encoded format
pub fn json<T>(self, json: &T) -> RequestBuilder
pub fn json<T>(self, json: &T) -> RequestBuilder
Send a JSON body.
Serializes the value to JSON and sets resulting bytes as the body.
Sets Content-Type header to application/json unless the header is already set.
§Optional
This requires the optional json feature enabled.
§Errors
Serialization can fail if T’s implementation of Serialize decides to
fail, or if T contains a map with non-string keys.
pub fn build(self) -> Result<Request, Error>
pub fn build(self) -> Result<Request, Error>
Build a Request, which can be inspected, modified and executed with
Client::execute().
pub fn build_split(self) -> (Client, Result<Request, Error>)
pub fn build_split(self) -> (Client, Result<Request, Error>)
Build a Request, which can be inspected, modified and executed with
Client::execute().
This is similar to RequestBuilder::build(), but also returns the
embedded Client.
pub fn send(self) -> impl Future<Output = Result<Response, Error>>
pub fn send(self) -> impl Future<Output = Result<Response, Error>>
Constructs the Request and sends it to the target URL, returning a future Response.
§Errors
This method fails if there was an error while sending request, redirect loop was detected or redirect limit was exhausted.
§Example
let response = reqwest::Client::new()
.get("https://hyper.rs")
.send()
.await?;pub fn try_clone(&self) -> Option<RequestBuilder>
pub fn try_clone(&self) -> Option<RequestBuilder>
Attempt to clone the RequestBuilder.
None is returned if the RequestBuilder can not be cloned,
i.e. if the request body is a stream.
§Examples
let client = reqwest::Client::new();
let builder = client.post("http://httpbin.org/post")
.body("from a &str!");
let clone = builder.try_clone();
assert!(clone.is_some());Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RequestBuilder
impl !RefUnwindSafe for RequestBuilder
impl !UnwindSafe for RequestBuilder
impl Send for RequestBuilder
impl Sync for RequestBuilder
impl Unpin for RequestBuilder
impl UnsafeUnpin for RequestBuilder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].