pub struct Client { /* private fields */ }Expand description
A simple extendable client wrapper for http request with extra url sanitization.
Implementations§
Source§impl Client
impl Client
Sourcepub fn set_front_policy(&mut self, policy: FrontPolicy)
pub fn set_front_policy(&mut self, policy: FrontPolicy)
Set the policy for enabling fronting. If fronting was previously unset this will set it, and
make it possible to enable (i.e FrontPolicy::Off will not enable it).
Calling this function sets a custom policy for this client, disconnecting it from the shared
fronting policy – i.e. changes applied through Client::set_shared_front_policy will not
be impact this client.
Set the fronting policy for this client to follow the shared policy.
Set the fronting policy for all clients using the shared policy.
Source§impl Client
impl Client
Sourcepub fn new_url<U>(
url: U,
timeout: Option<Duration>,
) -> Result<Self, HttpClientError>where
U: IntoUrl,
pub fn new_url<U>(
url: U,
timeout: Option<Duration>,
) -> Result<Self, HttpClientError>where
U: IntoUrl,
Attempt to create a new http client from a something that can be converted to a URL
Sourcepub fn builder<U>(url: U) -> Result<ClientBuilder, HttpClientError>where
U: IntoUrl,
pub fn builder<U>(url: U) -> Result<ClientBuilder, HttpClientError>where
U: IntoUrl,
Creates a ClientBuilder to configure a Client.
This is the same as ClientBuilder::new().
Sourcepub fn change_base_urls(&mut self, new_urls: Vec<Url>)
pub fn change_base_urls(&mut self, new_urls: Vec<Url>)
Update the set of hosts that this client uses when sending API requests.
Sourcepub fn clone_with_new_url(&self, new_url: Url) -> Self
pub fn clone_with_new_url(&self, new_url: Url) -> Self
Create new instance of Client using the provided base url and existing client config
Sourcepub fn current_url(&self) -> &Url
pub fn current_url(&self) -> &Url
Get the currently configured host that this client uses when sending API requests.
Sourcepub fn base_urls(&self) -> &[Url]
pub fn base_urls(&self) -> &[Url]
Get the currently configured host that this client uses when sending API requests.
Sourcepub fn base_urls_mut(&mut self) -> &mut [Url]
pub fn base_urls_mut(&mut self) -> &mut [Url]
Get a mutable reference to the hosts that this client uses when sending API requests.
Sourcepub fn change_retry_limit(&mut self, limit: usize)
pub fn change_retry_limit(&mut self, limit: usize)
Change the currently configured limit on the number of retries for a request.
Trait Implementations§
Source§impl ApiClientCore for Client
impl ApiClientCore for Client
Source§fn 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>
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,
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,
Source§fn maybe_rotate_hosts(&self, offending: Option<Url>)
fn maybe_rotate_hosts(&self, offending: Option<Url>)
Source§fn maybe_enable_fronting(&self, context: impl Debug)
fn maybe_enable_fronting(&self, context: impl Debug)
OnRetry this function will enable the
fronting if not already enabled.Source§fn 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>
"/api/v1/mixnodes?since=12345"). If the provided endpoint fails to parse as path (and
optionally query parameters). Read moreSource§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>>
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>>
Auto Trait Implementations§
impl !Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<C> ApiClient for Cwhere
C: ApiClientCore + Sync,
impl<C> ApiClient for Cwhere
C: ApiClientCore + Sync,
Source§fn create_get_request<P, K, V>(
&self,
path: P,
params: Params<'_, K, V>,
) -> Result<RequestBuilder, HttpClientError>
fn create_get_request<P, K, V>( &self, path: P, params: Params<'_, K, V>, ) -> Result<RequestBuilder, HttpClientError>
Source§fn create_post_request<P, B, K, V>(
&self,
path: P,
params: Params<'_, K, V>,
json_body: &B,
) -> Result<RequestBuilder, HttpClientError>
fn create_post_request<P, B, K, V>( &self, path: P, params: Params<'_, K, V>, json_body: &B, ) -> Result<RequestBuilder, HttpClientError>
Source§fn create_delete_request<P, K, V>(
&self,
path: P,
params: Params<'_, K, V>,
) -> Result<RequestBuilder, HttpClientError>
fn create_delete_request<P, K, V>( &self, path: P, params: Params<'_, K, V>, ) -> Result<RequestBuilder, HttpClientError>
Source§fn create_patch_request<P, B, K, V>(
&self,
path: P,
params: Params<'_, K, V>,
json_body: &B,
) -> Result<RequestBuilder, HttpClientError>
fn create_patch_request<P, B, K, V>( &self, path: P, params: Params<'_, K, V>, json_body: &B, ) -> Result<RequestBuilder, HttpClientError>
Source§fn send_get_request<'life0, 'life1, 'async_trait, P, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
fn send_get_request<'life0, 'life1, 'async_trait, P, K, V>( &'life0 self, path: P, params: Params<'life1, K, V>, ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
Source§fn send_post_request<'life0, 'life1, 'life2, 'async_trait, P, B, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
json_body: &'life2 B,
) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
fn send_post_request<'life0, 'life1, 'life2, 'async_trait, P, B, K, V>( &'life0 self, path: P, params: Params<'life1, K, V>, json_body: &'life2 B, ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
Source§fn send_delete_request<'life0, 'life1, 'async_trait, P, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
fn send_delete_request<'life0, 'life1, 'async_trait, P, K, V>( &'life0 self, path: P, params: Params<'life1, K, V>, ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
Source§fn send_patch_request<'life0, 'life1, 'life2, 'async_trait, P, B, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
json_body: &'life2 B,
) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
fn send_patch_request<'life0, 'life1, 'life2, 'async_trait, P, B, K, V>( &'life0 self, path: P, params: Params<'life1, K, V>, json_body: &'life2 B, ) -> Pin<Box<dyn Future<Output = Result<Response, HttpClientError>> + Send + 'async_trait>>
Source§fn get_json<'life0, 'life1, 'async_trait, P, T, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
fn get_json<'life0, 'life1, 'async_trait, P, T, K, V>( &'life0 self, path: P, params: Params<'life1, K, V>, ) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
["api", "v1", "mixnodes"], with tuple
defined key-value parameters, e.g. [("since", "12345")]. Attempt to parse the response
into the provided type T.Source§fn parse_response<'life0, 'async_trait, T>(
&'life0 self,
res: Response,
allow_empty: bool,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>where
T: DeserializeOwned + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn parse_response<'life0, 'async_trait, T>(
&'life0 self,
res: Response,
allow_empty: bool,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>where
T: DeserializeOwned + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
Source§fn get_response<'life0, 'life1, 'async_trait, P, T, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
fn get_response<'life0, 'life1, 'async_trait, P, T, K, V>( &'life0 self, path: P, params: Params<'life1, K, V>, ) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
["api", "v1", "mixnodes"], with tuple
defined key-value parameters, e.g. [("since", "12345")]. Attempt to parse the response
into the provided type T based on the content type headerSource§fn post_json<'life0, 'life1, 'life2, 'async_trait, P, B, T, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
json_body: &'life2 B,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>where
P: RequestPath + Send + Sync + 'async_trait,
B: Serialize + ?Sized + Sync + 'async_trait,
for<'a> T: Deserialize<'a> + '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,
fn post_json<'life0, 'life1, 'life2, 'async_trait, P, B, T, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
json_body: &'life2 B,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>where
P: RequestPath + Send + Sync + 'async_trait,
B: Serialize + ?Sized + Sync + 'async_trait,
for<'a> T: Deserialize<'a> + '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,
["api", "v1", "mixnodes"], with tuple
defined key-value parameters, e.g. [("since", "12345")]. Attempt to parse the response
into the provided type T.Source§fn delete_json<'life0, 'life1, 'async_trait, P, T, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
fn delete_json<'life0, 'life1, 'async_trait, P, T, K, V>( &'life0 self, path: P, params: Params<'life1, K, V>, ) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
["api", "v1", "mixnodes"], with
tuple defined key-value parameters, e.g. [("since", "12345")]. Attempt to parse the
response into the provided type T.Source§fn patch_json<'life0, 'life1, 'life2, 'async_trait, P, B, T, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
json_body: &'life2 B,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>where
P: RequestPath + Send + Sync + 'async_trait,
B: Serialize + ?Sized + Sync + 'async_trait,
for<'a> T: Deserialize<'a> + '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,
fn patch_json<'life0, 'life1, 'life2, 'async_trait, P, B, T, K, V>(
&'life0 self,
path: P,
params: Params<'life1, K, V>,
json_body: &'life2 B,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>where
P: RequestPath + Send + Sync + 'async_trait,
B: Serialize + ?Sized + Sync + 'async_trait,
for<'a> T: Deserialize<'a> + '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,
["api", "v1", "mixnodes"], with tuple
defined key-value parameters, e.g. [("since", "12345")]. Attempt to parse the response
into the provided type T.Source§fn get_json_from<'life0, 'async_trait, T, S>(
&'life0 self,
endpoint: S,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
fn get_json_from<'life0, 'async_trait, T, S>( &'life0 self, endpoint: S, ) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
get json data from the provided absolute endpoint, e.g. "/api/v1/mixnodes?since=12345".
Attempt to parse the response into the provided type T.Source§fn post_json_data_to<'life0, 'life1, 'async_trait, B, T, S>(
&'life0 self,
endpoint: S,
json_body: &'life1 B,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
fn post_json_data_to<'life0, 'life1, 'async_trait, B, T, S>( &'life0 self, endpoint: S, json_body: &'life1 B, ) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
post json data to the provided absolute endpoint, e.g. "/api/v1/mixnodes?since=12345".
Attempt to parse the response into the provided type T.Source§fn delete_json_from<'life0, 'async_trait, T, S>(
&'life0 self,
endpoint: S,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
fn delete_json_from<'life0, 'async_trait, T, S>( &'life0 self, endpoint: S, ) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
delete json data from the provided absolute endpoint, e.g.
"/api/v1/mixnodes?since=12345". Attempt to parse the response into the provided type T.Source§fn patch_json_data_at<'life0, 'life1, 'async_trait, B, T, S>(
&'life0 self,
endpoint: S,
json_body: &'life1 B,
) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
fn patch_json_data_at<'life0, 'life1, 'async_trait, B, T, S>( &'life0 self, endpoint: S, json_body: &'life1 B, ) -> Pin<Box<dyn Future<Output = Result<T, HttpClientError>> + Send + 'async_trait>>
patch json data at the provided absolute endpoint, e.g. "/api/v1/mixnodes?since=12345".
Attempt to parse the response into the provided type T.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more