Struct RestClient

Source
pub struct RestClient<'a, Strategy, Parser> {
    pub http_client: Client,
    pub base_url: Cow<'a, str>,
    pub strategy: Strategy,
    pub parser: Parser,
}
Expand description

Configurable REST client capable of executing signed RestRequests. Use this when integrating APIs that require Http in order to interact with resources. Each API will require a specific combination of Signer, Mac, signature Encoder, and HttpParser.

Fields§

§http_client: Client

HTTP reqwest::Client for executing signed reqwest::Requests.

§base_url: Cow<'a, str>

Base Url of the API being interacted with.

§strategy: Strategy

RestRequest build strategy for the API being interacted with that implements BuildStrategy.

An authenticated RestClient will utilise API specific Signer logic, a hashable Mac, and a signature Encoder. Where as a non authorised RestRequest may add any mandatory reqwest headers that are required.

§parser: Parser

HttpParser that deserialises RestRequest::Responses, and upon failure parses API errors returned from the server.

Implementations§

Source§

impl<Strategy, Parser> RestClient<'_, Strategy, Parser>
where Strategy: BuildStrategy, Parser: HttpParser,

Source

pub async fn execute<Request>( &self, request: Request, ) -> Result<(Request::Response, Metric), Parser::OutputError>
where Request: RestRequest,

Execute the provided RestRequest.

Source

pub fn build<Request>(&self, request: Request) -> Result<Request, SocketError>
where Request: RestRequest,

Use the provided RestRequest to construct a signed Http reqwest::Request.

Source

pub async fn measured_execution<Request>( &self, request: Request, ) -> Result<(StatusCode, Bytes, Metric), SocketError>
where Request: RestRequest,

Execute the built reqwest::Request using the reqwest::Client.

Measures and returns the Http request round trip duration.

Source§

impl<'a, Strategy, Parser> RestClient<'a, Strategy, Parser>

Source

pub fn new<Url: Into<Cow<'a, str>>>( base_url: Url, strategy: Strategy, parser: Parser, ) -> Self

Construct a new Self using the provided configuration.

Trait Implementations§

Source§

impl<'a, Strategy: Debug, Parser: Debug> Debug for RestClient<'a, Strategy, Parser>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, Strategy, Parser> Freeze for RestClient<'a, Strategy, Parser>
where Strategy: Freeze, Parser: Freeze,

§

impl<'a, Strategy, Parser> !RefUnwindSafe for RestClient<'a, Strategy, Parser>

§

impl<'a, Strategy, Parser> Send for RestClient<'a, Strategy, Parser>
where Strategy: Send, Parser: Send,

§

impl<'a, Strategy, Parser> Sync for RestClient<'a, Strategy, Parser>
where Strategy: Sync, Parser: Sync,

§

impl<'a, Strategy, Parser> Unpin for RestClient<'a, Strategy, Parser>
where Strategy: Unpin, Parser: Unpin,

§

impl<'a, Strategy, Parser> !UnwindSafe for RestClient<'a, Strategy, Parser>

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<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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T