Struct HttpRequest

Source
pub struct HttpRequest<C> { /* private fields */ }

Implementations§

Source§

impl<C> HttpRequest<C>

Source

pub fn set_uri<T>(self, uri: T) -> Self
where Uri: TryFrom<T>, <Uri as TryFrom<T>>::Error: Into<Error>,

Sets the URI for the HTTP request. Accepts any type that can be converted into a Uri.

§Examples
request.set_uri("https://example.com/path");
request.set_uri(Uri::from_static("https://example.com/path"));
Source

pub fn set_method<T>(self, method: T) -> Self
where Method: TryFrom<T>, <Method as TryFrom<T>>::Error: Into<Error>,

Sets the HTTP method for the request (GET, POST, PUT, etc.). Accepts any type that can be converted into a Method.

§Examples
request.set_method("POST");
request.set_method(Method::POST);
Source

pub fn set_header<K, T>(self, key: K, value: T) -> Self

Sets a header in the HTTP request. Note: For HTTP/2 requests, connection-specific headers will be automatically removed. The ‘host’ header is mandatory in HTTP/1.1 and will be added by default if not set.

§Examples
request.set_header("content-type", "application/json");
request.set_header(HeaderName::from_static("authorization"), "Bearer token");
Source

pub fn set_version(self, version: Version) -> Self

Sets the HTTP version for the request. Default version is HTTP/1.1 if not specified.

§Examples
request.set_version(Version::HTTP_11);
request.set_version(Version::HTTP_2);
Source

pub fn set_extension<T>(self, extension: T) -> Self
where T: Clone + Any + Send + Sync + 'static,

Adds a type-based extension to the request. Extensions can be used to store extra information that travels along with the request. The extension type must be Clone + Any + 'static.

Source§

impl HttpRequest<MonoioClient>

Source

pub async fn send(self) -> Result<HttpResponse<HttpBody>, Error>

Sends the HTTP request without a body. Returns a Result containing either the HTTP response or an error.

Source

pub async fn send_body( self, body: impl Into<Option<Bytes>>, ) -> Result<HttpResponse<HttpBody>, Error>

Sends the HTTP request with an optional body. The body can be provided as any type that can be converted into Option<Bytes>. Returns a Result containing either the HTTP response or an error.

§Examples
let response = request.send_body(Some(Bytes::from("request body"))).await?;
let response = request.send_body(None).await?; // No body

Auto Trait Implementations§

§

impl<C> !Freeze for HttpRequest<C>

§

impl<C> !RefUnwindSafe for HttpRequest<C>

§

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

§

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

§

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

§

impl<C> !UnwindSafe for HttpRequest<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