Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A simple extendable client wrapper for http request with extra url sanitization.

Implementations§

Source§

impl Client

Source

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.

Source

pub fn use_shared_front_policy(&mut self)

Set the fronting policy for this client to follow the shared policy.

Source

pub fn set_shared_front_policy(policy: FrontPolicy)

Set the fronting policy for all clients using the shared policy.

Source§

impl Client

Source

pub fn new(base_url: Url, timeout: Option<Duration>) -> Self

Create a new http Client

Source

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

Source

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().

Source

pub fn change_base_urls(&mut self, new_urls: Vec<Url>)

Update the set of hosts that this client uses when sending API requests.

Source

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

Source

pub fn current_url(&self) -> &Url

Get the currently configured host that this client uses when sending API requests.

Source

pub fn current_url_str(&self) -> &str

The wire-level request target this client is currently pointed at: the active host’s own URL, or - while fronting has selected one - that front’s URL instead. See Self::current_front_host for just the front’s host.

Source

pub fn current_front_host(&self) -> Option<&str>

The front host (domain or IP) currently selected for the active base url, if fronting has selected one for it.

Source

pub fn base_urls(&self) -> &[Url]

Get the currently configured host that this client uses when sending API requests.

Source

pub fn base_urls_mut(&mut self) -> &mut [Url]

Get a mutable reference to the hosts that this client uses when sending API requests.

Source

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

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. Read more
Source§

fn maybe_rotate_hosts(&self, offending: Option<Url>)

If multiple base urls are available rotate to next (e.g. when the current one resulted in an error) Read more
Source§

fn maybe_enable_fronting(&self, domain: Option<&str>, context: impl Debug)

If the fronting policy for the client is set to OnRetry or ConfiguredRetry this function will enable fronting if not already enabled. domain should be the host of the URL that triggered the failure, and is used by ConfiguredRetry to track failures per domain.
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). Read more
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.
Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<C> ApiClient for C
where C: ApiClientCore + Sync,

Source§

fn create_get_request<P, K, V>( &self, path: P, params: Params<'_, K, V>, ) -> Result<RequestBuilder, HttpClientError>
where P: RequestPath, K: AsRef<str>, V: AsRef<str>,

Create an HTTP GET Request with the provided path and parameters
Source§

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

Create an HTTP POST Request with the provided path, parameters, and json body
Source§

fn create_delete_request<P, K, V>( &self, path: P, params: Params<'_, K, V>, ) -> Result<RequestBuilder, HttpClientError>
where P: RequestPath, K: AsRef<str>, V: AsRef<str>,

Create an HTTP DELETE Request with the provided path and parameters
Source§

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

Create an HTTP PATCH Request with the provided path, parameters, and json body
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>>
where P: RequestPath + Send + 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,

Create and send an HTTP GET Request with the provided path and parameters
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>>
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 an HTTP POST Request with the provided path, parameters, and json data
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>>
where P: RequestPath + Send + 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,

Create and send an HTTP DELETE Request with the provided path and parameters
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>>
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 an HTTP PATCH Request with the provided path, parameters, and json data
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>>
where P: RequestPath + Send + 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,

‘get’ json data from the segment-defined path, e.g. ["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,

Attempt to parse a response object from an HTTP response
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>>
where P: RequestPath + Send + 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,

‘get’ data from the segment-defined path, e.g. ["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 header
Source§

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,

‘post’ json data to the segment-defined path, e.g. ["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>>
where P: RequestPath + Send + 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,

‘delete’ json data from the segment-defined path, e.g. ["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,

‘patch’ json data at the segment-defined path, e.g. ["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>>
where for<'a> T: Deserialize<'a> + 'async_trait, S: AsRef<str> + Sync + Send + 'async_trait, Self: Sync + 'async_trait, 'life0: '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>>
where B: Serialize + ?Sized + Sync + 'async_trait, for<'a> T: Deserialize<'a> + 'async_trait, S: AsRef<str> + Sync + Send + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: '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>>
where for<'a> T: Deserialize<'a> + 'async_trait, S: AsRef<str> + Sync + Send + 'async_trait, Self: Sync + 'async_trait, 'life0: '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>>
where B: Serialize + ?Sized + Sync + 'async_trait, for<'a> T: Deserialize<'a> + 'async_trait, S: AsRef<str> + Sync + Send + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: '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> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more