ApiClientCore

Trait ApiClientCore 

Source
pub trait ApiClientCore {
    // Required methods
    fn create_request<P, B, K, V>(
        &self,
        method: Method,
        path: P,
        params: Params<'_, K, V>,
        body: Option<&B>,
    ) -> Result<RequestBuilder, HttpClientError>
       where P: RequestPath,
             B: Serialize + ?Sized,
             K: AsRef<str>,
             V: AsRef<str>;
    fn send<'life0, 'async_trait>(
        &'life0 self,
        request: RequestBuilder,
    ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn create_request_endpoint<B, S>(
        &self,
        method: Method,
        endpoint: S,
        body: Option<&B>,
    ) -> Result<RequestBuilder, HttpClientError>
       where B: Serialize + ?Sized,
             S: AsRef<str> { ... }
    fn send_request<'life0, 'life1, 'life2, 'async_trait, P, B, K, V>(
        &'life0 self,
        method: Method,
        path: P,
        params: Params<'life1, K, V>,
        json_body: Option<&'life2 B>,
    ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
       where P: RequestPath + Send + Sync + 'async_trait,
             B: Serialize + ?Sized + Sync + 'async_trait,
             K: AsRef<str> + Sync + 'async_trait,
             V: AsRef<str> + Sync + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Core functionality required for types acting as API clients.

This trait defines the “skinny waist” of behaviors that are required by an API client. More likely downstream libraries should use functions from the ApiClient interface which provide a more ergonomic set of functionalities.

Required Methods§

Source

fn create_request<P, B, K, V>( &self, method: Method, path: P, params: Params<'_, K, V>, body: Option<&B>, ) -> Result<RequestBuilder, HttpClientError>
where P: RequestPath, B: Serialize + ?Sized, K: AsRef<str>, V: AsRef<str>,

Create an HTTP request using the host configured in this client.

Source

fn send<'life0, 'async_trait>( &'life0 self, request: RequestBuilder, ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a created HTTP request.

A RequestBuilder can be created with ApiClientCore::create_request or ApiClientCore::create_request_endpoint or if absolutely necessary, using reqwest tooling directly.

Provided Methods§

Source

fn create_request_endpoint<B, S>( &self, method: Method, endpoint: S, body: Option<&B>, ) -> Result<RequestBuilder, HttpClientError>
where B: Serialize + ?Sized, S: AsRef<str>,

Create an HTTP request using the host configured in this client and an API endpoint (i.e. "/api/v1/mixnodes?since=12345"). If the provided endpoint fails to parse as path (and optionally query parameters).

Endpoint Examples

  • "/api/v1/mixnodes?since=12345"
  • "/api/v1/mixnodes"
  • "/api/v1/mixnodes/img.png"
  • "/api/v1/mixnodes/img.png?since=12345"
  • "/"
  • "/?since=12345"
  • ""
  • "?since=12345"

for more information about URL percent encodings see url::Url::set_path()

Source

fn send_request<'life0, 'life1, 'life2, 'async_trait, P, B, K, V>( &'life0 self, method: Method, path: P, params: Params<'life1, K, V>, json_body: Option<&'life2 B>, ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
where P: RequestPath + Send + Sync + 'async_trait, B: Serialize + ?Sized + Sync + 'async_trait, K: AsRef<str> + Sync + 'async_trait, V: AsRef<str> + Sync + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create and send a created HTTP 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§