IntoRequest

Trait IntoRequest 

Source
pub trait IntoRequest<R = ClientResponse>: Sized {
    // Required method
    fn into_request(
        self,
        req: ClientRequest,
    ) -> impl Future<Output = Result<R, RequestError>> + 'static;
}
Expand description

The IntoRequest trait allows types to be used as the body of a request to a HTTP endpoint or server function.

IntoRequest allows for types handle the calling of ClientRequest::send where the result is then passed to FromResponse to decode the response.

You can think of the IntoRequest and FromResponse traits are “inverse” traits of the axum FromRequest and IntoResponse traits. Just like a type can be decoded from a request via FromRequest, a type can be encoded into a request via IntoRequest.

§Generic State

IntoRequest is generic over the response type R which defaults to ClientResponse. The default ClientResponse is the base response type that internally wraps reqwest::Response.

However, some responses might need state from the initial request to properly decode the response. Most state can be extended via the .extension() method on ClientRequest. In some cases, like websockets, the response needs to retain an initial connection from the request. Here, you can use the R generic to specify a concrete response type. The resulting type that implements FromResponse must also be generic over the same R type.

Required Methods§

Source

fn into_request( self, req: ClientRequest, ) -> impl Future<Output = Result<R, RequestError>> + 'static

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<A, R> IntoRequest<R> for (A,)
where A: IntoRequest<R> + 'static + Send,

Source§

fn into_request( self, req: ClientRequest, ) -> impl Future<Output = Result<R, RequestError>> + 'static

Implementors§

Source§

impl IntoRequest for FileStream

Source§

impl IntoRequest for Streaming<String>

Source§

impl IntoRequest for Request

Implementation of IntoRequest for axum::extract::Request.

This allows converting an axum::Request (from server-side extraction) into a ClientRequest that can be sent as an HTTP request. The request’s headers and body are transferred from the axum request to the client request.

Source§

impl IntoRequest for ByteStream

Source§

impl<S> IntoRequest for MultipartFormData<S>

Source§

impl<T> IntoRequest for Form<T>
where T: Serialize + 'static + DeserializeOwned,

Source§

impl<T> IntoRequest for Json<T>
where T: Serialize + 'static + DeserializeOwned,

Source§

impl<T: DeserializeOwned + Serialize + 'static + Send, E: Encoding> IntoRequest for Streaming<T, E>