RequestExt

Trait RequestExt 

Source
pub trait RequestExt<B>: Sized {
Show 16 methods // Required methods fn json<T: Serialize + ?Sized>( self, body: &T, ) -> Result<Request<Full<Bytes>>>; fn query<Q: Serialize + ?Sized>(self, query: &Q) -> Result<Request<B>>; fn multipart( self, form: Form, ) -> Result<Request<UnsyncBoxBody<Bytes, BodyError>>>; fn form<T: Serialize + ?Sized>( self, form: &T, ) -> Result<Request<Full<Bytes>>>; fn stream<S: Stream>(self, stream: S) -> Result<Request<StreamBody<S>>>; fn plain_text(self, body: impl Into<Bytes>) -> Result<Request<Full<Bytes>>>; fn empty(self) -> Result<Request<Empty<Bytes>>>; fn collect_into_bytes( self, ) -> impl Future<Output = Result<Request<Full<Bytes>>>> + Send where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync; fn with_version(self, version: Version) -> Request<B>; fn with_method(self, method: Method) -> Request<B>; fn with_header<K>(self, key: K, value: HeaderValue) -> Request<B> where K: IntoHeaderName; fn with_headers(self, header_map: HeaderMap) -> Request<B>; fn send<S, R>( self, client: S, ) -> impl Future<Output = Result<S::Response>> + Send where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync, S: Service<Request<ClientBody>, Response = Response<R>> + Send, R: Body, <S as Service<Request<ClientBody>>>::Error: Error + Send + Sync + 'static, <S as Service<Request<ClientBody>>>::Future: Send; // Provided methods fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Request<B> where U: Display, P: Display, Self: Sized { ... } fn bearer_auth<T>(self, token: T) -> Request<B> where T: Display { ... } fn send_timeout<S, R>( self, client: S, timeout: Duration, ) -> impl Future<Output = Result<Response<MaybeAbort<R>>>> + Send where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync, S: Service<Request<ClientBody>, Response = Response<R>> + Send, <S as Service<Request<ClientBody>>>::Error: Error + Send + Sync + 'static, <S as Service<Request<ClientBody>>>::Future: Send, R: Body, Self: Sized { ... }
}
Expand description

Extension trait for http::Request.

Required Methods§

Source

fn json<T: Serialize + ?Sized>(self, body: &T) -> Result<Request<Full<Bytes>>>

Available on crate feature json only.
Source

fn query<Q: Serialize + ?Sized>(self, query: &Q) -> Result<Request<B>>

Available on crate feature query only.
Source

fn multipart( self, form: Form, ) -> Result<Request<UnsyncBoxBody<Bytes, BodyError>>>

Available on crate feature multipart only.
Source

fn form<T: Serialize + ?Sized>(self, form: &T) -> Result<Request<Full<Bytes>>>

Available on crate feature form only.
Source

fn stream<S: Stream>(self, stream: S) -> Result<Request<StreamBody<S>>>

Source

fn plain_text(self, body: impl Into<Bytes>) -> Result<Request<Full<Bytes>>>

Source

fn empty(self) -> Result<Request<Empty<Bytes>>>

Source

fn collect_into_bytes( self, ) -> impl Future<Output = Result<Request<Full<Bytes>>>> + Send
where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync,

Source

fn with_version(self, version: Version) -> Request<B>

Source

fn with_method(self, method: Method) -> Request<B>

Source

fn with_header<K>(self, key: K, value: HeaderValue) -> Request<B>
where K: IntoHeaderName,

Source

fn with_headers(self, header_map: HeaderMap) -> Request<B>

Source

fn send<S, R>( self, client: S, ) -> impl Future<Output = Result<S::Response>> + Send
where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync, S: Service<Request<ClientBody>, Response = Response<R>> + Send, R: Body, <S as Service<Request<ClientBody>>>::Error: Error + Send + Sync + 'static, <S as Service<Request<ClientBody>>>::Future: Send,

Provided Methods§

Source

fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Request<B>
where U: Display, P: Display, Self: Sized,

Available on crate feature auth only.
Source

fn bearer_auth<T>(self, token: T) -> Request<B>
where T: Display,

Available on crate feature auth only.
Source

fn send_timeout<S, R>( self, client: S, timeout: Duration, ) -> impl Future<Output = Result<Response<MaybeAbort<R>>>> + Send
where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync, S: Service<Request<ClientBody>, Response = Response<R>> + Send, <S as Service<Request<ClientBody>>>::Error: Error + Send + Sync + 'static, <S as Service<Request<ClientBody>>>::Future: Send, R: Body, Self: Sized,

Available on crate feature rt-tokio only.

Send the request to a service with a timeout layer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<B> RequestExt<B> for Request<B>
where B: Send,

Source§

fn json<T: Serialize + ?Sized>(self, body: &T) -> Result<Request<Full<Bytes>>>

Available on crate feature json only.

Set the request body as JSON.

Source§

fn query<Q: Serialize + ?Sized>(self, query: &Q) -> Result<Request<B>>

Available on crate feature query only.

Add query parameters to the request URI.

Source§

fn multipart(self, form: Form) -> Result<Request<DynBody>>

Available on crate feature multipart only.

Set the request body as multipart form data.

Source§

fn form<T: Serialize + ?Sized>(self, form: &T) -> Result<Request<Full<Bytes>>>

Available on crate feature form only.

Set the request body as form data.

Source§

fn plain_text(self, body: impl Into<Bytes>) -> Result<Request<Full<Bytes>>>

Set the request body as plain text.

Source§

fn stream<S: Stream>(self, stream: S) -> Result<Request<StreamBody<S>>>

Set the request body as a stream.

Source§

fn empty(self) -> Result<Request<Empty<Bytes>>>

Set the request body as empty.

Source§

async fn collect_into_bytes(self) -> Result<Request<Full<Bytes>>>
where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync,

Collect the request body stream into bytes. This is useful when you want to clone the request.

Source§

fn with_version(self, version: Version) -> Request<B>

Set the request HTTP version.

Source§

fn with_method(self, method: Method) -> Request<B>

Set the request method.

Source§

fn with_header<K>(self, key: K, value: HeaderValue) -> Request<B>
where K: IntoHeaderName,

Set a request header.

Source§

fn with_headers(self, header_map: HeaderMap) -> Request<B>

Extend multiple request headers.

Source§

async fn send<S, R>(self, client: S) -> Result<S::Response>
where B: Body<Data = Bytes> + Send + 'static, B::Error: Error + Send + Sync, S: Service<Request<ClientBody>, Response = Response<R>> + Send, R: Body, <S as Service<Request<ClientBody>>>::Error: Error + Send + Sync + 'static, <S as Service<Request<ClientBody>>>::Future: Send,

Send the request to a service.

If you enabled any decompression feature, the response body will be automatically decompressed.

Implementors§