Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required method
    fn send(
        &self,
        request: ClientRequest,
    ) -> impl Future<Output = Result<ClientResponse, HttpClientError>> + Send;

    // Provided methods
    fn get(
        &self,
        url: impl Into<String> + Send,
    ) -> impl Future<Output = Result<ClientResponse, HttpClientError>> + Send { ... }
    fn post(
        &self,
        url: impl Into<String> + Send,
        body: impl Into<Vec<u8>> + Send,
    ) -> impl Future<Output = Result<ClientResponse, HttpClientError>> + Send { ... }
}
Expand description

Outbound HTTP client (Symfony HttpClientInterface analogue).

Required Methods§

Source

fn send( &self, request: ClientRequest, ) -> impl Future<Output = Result<ClientResponse, HttpClientError>> + Send

Sends request and returns the response.

§Errors

Returns HttpClientError on transport or construction failure.

Provided Methods§

Source

fn get( &self, url: impl Into<String> + Send, ) -> impl Future<Output = Result<ClientResponse, HttpClientError>> + Send

Convenience GET.

§Errors

Propagates Self::send.

Source

fn post( &self, url: impl Into<String> + Send, body: impl Into<Vec<u8>> + Send, ) -> impl Future<Output = Result<ClientResponse, HttpClientError>> + Send

Convenience POST with optional body bytes.

§Errors

Propagates Self::send.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§