Trait HttpClientExt

pub trait HttpClientExt<State>:
    Sized
    + HttpClientExtSealed<State>
    + Send
    + Sync
    + 'static {
    type ExecuteResponse;
    type ExecuteError;

    // Required methods
    fn get(
        &self,
        url: impl IntoUrl,
    ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>;
    fn post(
        &self,
        url: impl IntoUrl,
    ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>;
    fn put(
        &self,
        url: impl IntoUrl,
    ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>;
    fn patch(
        &self,
        url: impl IntoUrl,
    ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>;
    fn delete(
        &self,
        url: impl IntoUrl,
    ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>;
    fn head(
        &self,
        url: impl IntoUrl,
    ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>;
    fn request(
        &self,
        method: Method,
        url: impl IntoUrl,
    ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>;
    fn execute(
        &self,
        ctx: Context<State>,
        request: Request<Body>,
    ) -> impl Future<Output = Result<Self::ExecuteResponse, Self::ExecuteError>>;
}
Expand description

Extends an Http Client with high level features, to facilitate the creation and sending of http requests, in a more ergonomic way.

Required Associated Types§

type ExecuteResponse

The response type returned by the execute method.

type ExecuteError

The error type returned by the execute method.

Required Methods§

fn get( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>

Convenience method to make a GET request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

fn post( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>

Convenience method to make a POST request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

fn put( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>

Convenience method to make a PUT request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

fn patch( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>

Convenience method to make a PATCH request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

fn delete( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>

Convenience method to make a DELETE request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

fn head( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>

Convenience method to make a HEAD request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

fn request( &self, method: Method, url: impl IntoUrl, ) -> RequestBuilder<'_, Self, State, Self::ExecuteResponse>

Start building a Request with the Method and Url.

Returns a RequestBuilder, which will allow setting headers and the request body before sending.

§Errors

This method fails whenever the supplied Url cannot be parsed.

fn execute( &self, ctx: Context<State>, request: Request<Body>, ) -> impl Future<Output = Result<Self::ExecuteResponse, Self::ExecuteError>>

Executes a Request.

§Errors

This method fails if there was an error while sending request.

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.

Implementors§

§

impl<State, S, Body> HttpClientExt<State> for S
where S: Service<State, Request<Body>, Response = Response<Body>>, <S as Service<State, Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send>>,

§

type ExecuteResponse = Response<Body>

§

type ExecuteError = <S as Service<State, Request<Body>>>::Error