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: ClientHTTP reqwest::Client for executing signed reqwest::Requests.
base_url: Cow<'a, str>Base Url of the API being interacted with.
strategy: StrategyRestRequest 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: ParserHttpParser that deserialises RestRequest::Responses, and upon failure parses
API errors returned from the server.
Implementations§
Source§impl<'a, Strategy, Parser> RestClient<'a, Strategy, Parser>where
Strategy: BuildStrategy,
Parser: HttpParser,
impl<'a, Strategy, Parser> RestClient<'a, Strategy, Parser>where
Strategy: BuildStrategy,
Parser: HttpParser,
Sourcepub async fn execute<Request>(
&self,
request: Request,
) -> Result<(Request::Response, Metric), Parser::OutputError>where
Request: RestRequest,
pub async fn execute<Request>(
&self,
request: Request,
) -> Result<(Request::Response, Metric), Parser::OutputError>where
Request: RestRequest,
Execute the provided RestRequest.
Sourcepub fn build<Request>(&self, request: Request) -> Result<Request, SocketError>where
Request: RestRequest,
pub fn build<Request>(&self, request: Request) -> Result<Request, SocketError>where
Request: RestRequest,
Use the provided RestRequest to construct a signed Http reqwest::Request.
Sourcepub async fn measured_execution<Request>(
&self,
request: Request,
) -> Result<(StatusCode, Bytes, Metric), SocketError>where
Request: RestRequest,
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.