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;
fn maybe_rotate_hosts(&self, offending_url: Option<Url>);
fn maybe_enable_fronting(&self, context: impl Debug);
// 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§
Sourcefn create_request<P, B, K, V>(
&self,
method: Method,
path: P,
params: Params<'_, K, V>,
body: Option<&B>,
) -> Result<RequestBuilder, HttpClientError>
fn create_request<P, B, K, V>( &self, method: Method, path: P, params: Params<'_, K, V>, body: Option<&B>, ) -> Result<RequestBuilder, HttpClientError>
Create an HTTP request using the host configured in this client.
Sourcefn 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,
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.
Sourcefn maybe_rotate_hosts(&self, offending_url: Option<Url>)
fn maybe_rotate_hosts(&self, offending_url: Option<Url>)
If multiple base urls are available rotate to next (e.g. when the current one resulted in an error)
Takes an optional URL argument. If this is none, the current host will be updated automatically. If a url is provided first check that the CURRENT host matches the hostname in the URL before triggering a rotation. This is meant to prevent parallel requests that fail from rotating the host multiple times.
Sourcefn maybe_enable_fronting(&self, context: impl Debug)
fn maybe_enable_fronting(&self, context: impl Debug)
If the fronting policy for the client is set to OnRetry this function will enable the
fronting if not already enabled.
Provided Methods§
Sourcefn create_request_endpoint<B, S>(
&self,
method: Method,
endpoint: S,
body: Option<&B>,
) -> Result<RequestBuilder, HttpClientError>
fn create_request_endpoint<B, S>( &self, method: Method, endpoint: S, body: Option<&B>, ) -> Result<RequestBuilder, HttpClientError>
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()
Sourcefn 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>>
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>>
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.