pub struct RequestBuilder<'a> { /* private fields */ }async-tls-native or async-tls-rustls-aws-lc-rs or async-tls-rustls-ring only.Expand description
Builds and executes a single request against an existing Client.
Create a builder from Client::request or the verb helpers such as
Client::get and Client::post.
See also:
examples/request_helpers.rsexamples/request_overrides.rsexamples/streaming.rs
§Example
use reqx::prelude::Client;
let client = Client::builder("https://api.example.com").build()?;
let response = client
.post("/v1/items")
.idempotency_key("item-1")?
.query_pair("verbose", "true")
.json(&serde_json::json!({ "name": "demo" }))?
.send_response()
.await?;
let _status = response.status();Implementations§
Source§impl<'a> RequestBuilder<'a>
impl<'a> RequestBuilder<'a>
Sourcepub fn header(self, name: HeaderName, value: HeaderValue) -> Self
Available on crate feature _async only.
pub fn header(self, name: HeaderName, value: HeaderValue) -> Self
_async only.Adds a header to this request.
See also examples/request_helpers.rs.
Sourcepub fn try_header(self, name: &str, value: &str) -> Result<Self>
Available on crate feature _async only.
pub fn try_header(self, name: &str, value: &str) -> Result<Self>
_async only.Parses and adds a header to this request.
Sourcepub fn idempotency_key(self, key: &str) -> Result<Self>
Available on crate feature _async only.
pub fn idempotency_key(self, key: &str) -> Result<Self>
_async only.Sets the Idempotency-Key header for retry-safe mutations.
Sourcepub fn query_pair(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
Available on crate feature _async only.
pub fn query_pair( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
_async only.Appends one query parameter pair.
Sourcepub fn query_pairs<K, V, I>(self, pairs: I) -> Self
Available on crate feature _async only.
pub fn query_pairs<K, V, I>(self, pairs: I) -> Self
_async only.Appends multiple query parameter pairs.
Sourcepub fn query<T>(self, params: &T) -> Result<Self>
Available on crate feature _async only.
pub fn query<T>(self, params: &T) -> Result<Self>
_async only.Serializes and appends query parameters from params.
Sourcepub fn body(self, body: impl Into<Bytes>) -> Self
Available on crate feature _async only.
pub fn body(self, body: impl Into<Bytes>) -> Self
_async only.Sets a fully buffered request body.
Sourcepub fn body_stream<S, E>(self, stream: S) -> Self
Available on crate feature _async only.
pub fn body_stream<S, E>(self, stream: S) -> Self
_async only.Sets a streaming request body.
Sourcepub fn body_reader<R>(self, reader: R) -> Self
Available on crate feature _async only.
pub fn body_reader<R>(self, reader: R) -> Self
_async only.Streams an async reader as the request body.
See also examples/streaming.rs.
Sourcepub fn body_reader_with_length<R>(
self,
reader: R,
content_length: u64,
) -> Result<Self>
Available on crate feature _async only.
pub fn body_reader_with_length<R>( self, reader: R, content_length: u64, ) -> Result<Self>
_async only.Streams an async reader as the request body and sets Content-Length.
Sourcepub fn json<T>(self, payload: &T) -> Result<Self>
Available on crate feature _async only.
pub fn json<T>(self, payload: &T) -> Result<Self>
_async only.Serializes payload as JSON and sets Content-Type: application/json.
See also examples/basic_json.rs.
Sourcepub fn form<T>(self, payload: &T) -> Result<Self>
Available on crate feature _async only.
pub fn form<T>(self, payload: &T) -> Result<Self>
_async only.Serializes payload as form data and sets the form content type.
Sourcepub fn timeout(self, timeout: Duration) -> Self
Available on crate feature _async only.
pub fn timeout(self, timeout: Duration) -> Self
_async only.Overrides the per-attempt request timeout for this request.
A zero duration is rejected by send or send_stream.
Sourcepub fn total_timeout(self, total_timeout: Duration) -> Self
Available on crate feature _async only.
pub fn total_timeout(self, total_timeout: Duration) -> Self
_async only.Overrides the overall deadline for this request.
A zero duration is rejected by send or send_stream.
Sourcepub fn max_response_body_bytes(self, max_response_body_bytes: usize) -> Self
Available on crate feature _async only.
pub fn max_response_body_bytes(self, max_response_body_bytes: usize) -> Self
_async only.Overrides the buffered response body size limit for this request.
Sourcepub fn retry_policy(self, retry_policy: RetryPolicy) -> Self
Available on crate feature _async only.
pub fn retry_policy(self, retry_policy: RetryPolicy) -> Self
_async only.Overrides the retry policy for this request.
See also examples/request_overrides.rs.
Sourcepub fn redirect_policy(self, redirect_policy: RedirectPolicy) -> Self
Available on crate feature _async only.
pub fn redirect_policy(self, redirect_policy: RedirectPolicy) -> Self
_async only.Overrides redirect handling for this request.
Sourcepub fn status_policy(self, status_policy: StatusPolicy) -> Self
Available on crate feature _async only.
pub fn status_policy(self, status_policy: StatusPolicy) -> Self
_async only.Overrides status handling for this request.
Sourcepub fn auto_accept_encoding(self, enabled: bool) -> Self
Available on crate feature _async only.
pub fn auto_accept_encoding(self, enabled: bool) -> Self
_async only.Overrides automatic Accept-Encoding injection for this request.
Sourcepub async fn send(self) -> Result<Response>
Available on crate feature _async only.
pub async fn send(self) -> Result<Response>
_async only.Executes the request and applies the effective StatusPolicy.
Sourcepub async fn send_stream(self) -> Result<ResponseStream>
Available on crate feature _async only.
pub async fn send_stream(self) -> Result<ResponseStream>
_async only.Executes the request and returns a streaming response body.
Non-success HTTP statuses still follow the effective StatusPolicy.
See also examples/streaming.rs.
Sourcepub async fn download_to_writer<W>(self, writer: &mut W) -> Result<u64>
Available on crate feature _async only.
pub async fn download_to_writer<W>(self, writer: &mut W) -> Result<u64>
_async only.Streams the response body into writer.
See also examples/streaming.rs.
Sourcepub async fn download_to_writer_limited<W>(
self,
writer: &mut W,
max_bytes: usize,
) -> Result<u64>
Available on crate feature _async only.
pub async fn download_to_writer_limited<W>( self, writer: &mut W, max_bytes: usize, ) -> Result<u64>
_async only.Streams the response body into writer, enforcing max_bytes.
See also examples/streaming.rs.
Sourcepub async fn send_json<T>(self) -> Result<T>where
T: DeserializeOwned,
Available on crate feature _async only.
pub async fn send_json<T>(self) -> Result<T>where
T: DeserializeOwned,
_async only.Executes the request, buffers the body, and deserializes it as JSON.
Sourcepub async fn send_response(self) -> Result<Response>
Available on crate feature _async only.
pub async fn send_response(self) -> Result<Response>
_async only.Executes the request and always returns a buffered crate::Response
for HTTP status responses.
Sourcepub async fn send_response_stream(self) -> Result<ResponseStream>
Available on crate feature _async only.
pub async fn send_response_stream(self) -> Result<ResponseStream>
_async only.Executes the request and always returns a streaming response for HTTP status responses.