Skip to main content

RequestBuilder

Struct RequestBuilder 

Source
pub struct RequestBuilder<C = HttpConnector> { /* private fields */ }
Expand description

Builder for a single HTTP request.

Created via Client::get(), Client::post(), etc.

Implementations§

Source§

impl<C> RequestBuilder<C>
where C: Connect + Clone + Send + Sync + 'static,

Source

pub fn header(self, key: &str, value: &str) -> Result<Self, OxiHttpError>

Add a request header.

Source

pub fn headers(self, map: HeaderMap) -> Self

Add multiple headers from a HeaderMap.

Source

pub fn bearer_token(self, token: &str) -> Result<Self, OxiHttpError>

Set a Bearer token for the Authorization header.

Source

pub fn basic_auth( self, username: &str, password: Option<&str>, ) -> Result<Self, OxiHttpError>

Set Basic authentication for the Authorization header.

Source

pub fn body(self, b: impl Into<Bytes>) -> Self

Set the request body as raw bytes.

Source

pub fn json<T: Serialize>(self, value: &T) -> Result<Self, OxiHttpError>

Set the request body as JSON, automatically setting the Content-Type header.

Source

pub fn form(self, form_body: &FormBody) -> Self

Set the request body as URL-encoded form data.

Source

pub fn multipart(self, builder: MultipartBuilder) -> Self

Set the request body from a MultipartBuilder, automatically setting the Content-Type: multipart/form-data; boundary=… header.

The Content-Type is only set if the caller has not already provided one. This allows overriding the header with an explicit .header() call made before .multipart().

§Example
use oxihttp_client::Client;
use oxihttp_core::MultipartBuilder;

let client = Client::builder().build()?;
let builder = MultipartBuilder::new().add_text("field", "value");
let resp = client.post("http://example.com/upload")?
    .multipart(builder)
    .send()
    .await?;
Source

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

Set a per-request timeout.

Source

pub async fn send(self) -> Result<Response, OxiHttpError>

Send the request and return the response.

Respects retry policy and per-request timeout. Before the first attempt the before_request hook is called on each registered middleware; after a successful response after_response is called with the final status and elapsed wall-clock time.

Auto Trait Implementations§

§

impl<C = HttpConnector> !Freeze for RequestBuilder<C>

§

impl<C = HttpConnector> !RefUnwindSafe for RequestBuilder<C>

§

impl<C> Send for RequestBuilder<C>
where C: Send,

§

impl<C> Sync for RequestBuilder<C>
where C: Sync,

§

impl<C> Unpin for RequestBuilder<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for RequestBuilder<C>
where C: UnsafeUnpin,

§

impl<C = HttpConnector> !UnwindSafe for RequestBuilder<C>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more