pub trait RequestHandler<'a> {
    const BASE_URL: &'static str;
    const API_KEY: &'static str = "apiKey";

    // Required methods
    fn client(&self) -> &Client;
    fn api_key(&self) -> &'a str;
    fn on_error(&self, status_code: StatusCode);

    // Provided methods
    fn concentrate_endpoint(endpoint: &str) -> String { ... }
    fn build_request(
        &self,
        endpoint: &str,
        parameters: &ParameterHashMap<'a>
    ) -> RequestBuilder { ... }
    fn build_parameters<Function>(
        &self,
        function: Function
    ) -> ParameterHashMap<'a>
       where Function: FnOnce(&mut ParameterHashMap<'a>) { ... }
    fn request<'life0, 'life1, 'async_trait, T>(
        &'life0 self,
        endpoint: &'life1 str,
        parameters: ParameterHashMap<'a>
    ) -> Pin<Box<dyn Future<Output = Result<T, ()>> + Send + 'async_trait>>
       where T: for<'de> Deserialize<'de> + 'async_trait,
             Self: Sync + 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

A trait for handling HTTP requests.

Required Associated Constants§

source

const BASE_URL: &'static str

The base URL for the requests.

Provided Associated Constants§

source

const API_KEY: &'static str = "apiKey"

The API key as string used for authentication.

Required Methods§

source

fn client(&self) -> &Client

Returns the HTTP client.

source

fn api_key(&self) -> &'a str

Returns the API key.

source

fn on_error(&self, status_code: StatusCode)

Handles an error response with the given status code.

Provided Methods§

source

fn concentrate_endpoint(endpoint: &str) -> String

Concentrates the base URL and endpoint into a complete URL.

source

fn build_request( &self, endpoint: &str, parameters: &ParameterHashMap<'a> ) -> RequestBuilder

Builds a request using the provided endpoint and parameters.

source

fn build_parameters<Function>(&self, function: Function) -> ParameterHashMap<'a>where Function: FnOnce(&mut ParameterHashMap<'a>),

Builds the parameter hashmap using the given function.

source

fn request<'life0, 'life1, 'async_trait, T>( &'life0 self, endpoint: &'life1 str, parameters: ParameterHashMap<'a> ) -> Pin<Box<dyn Future<Output = Result<T, ()>> + Send + 'async_trait>>where T: for<'de> Deserialize<'de> + 'async_trait, Self: Sync + 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sends an HTTP request with the given endpoint and parameters, and returns the parsed response.

Implementors§