Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Default {
    type Error;

    // Required methods
    fn get(
        &self,
        url: String,
        headers: &Headers,
        payload: &Query,
    ) -> impl Future<Output = Result<String, Self::Error>> + Send;
    fn post(
        &self,
        url: String,
        headers: &Headers,
        payload: &Query,
    ) -> impl Future<Output = Result<String, Self::Error>> + Send;
}
Expand description

A trait that can be implemented for any HTTP client library in Rust so we can use any library easily.

Required Associated Types§

Source

type Error

HttpClient error type

Required Methods§

Source

fn get( &self, url: String, headers: &Headers, payload: &Query, ) -> impl Future<Output = Result<String, Self::Error>> + Send

Function for sending GET requests

Source

fn post( &self, url: String, headers: &Headers, payload: &Query, ) -> impl Future<Output = Result<String, Self::Error>> + Send

Function for sending POST requests

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl HttpClient for ReqwestClient

Implements all functions of HttpClient for reqwest

Source§

impl HttpClient for TestClient

Implements a test HTTP client Should just log request data at debug level