pub struct Client { /* private fields */ }Expand description
An HTTP client for connectors. Cheap to clone; build one in new() and
reuse it. See the module docs.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Result<Self, FaucetError>
pub fn new() -> Result<Self, FaucetError>
A client with the ClientBuilder defaults.
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
A builder.
Sourcepub fn inner(&self) -> &Client
pub fn inner(&self) -> &Client
The underlying reqwest client, for request shapes this type does not
cover. It follows same-origin redirects only: a request sent straight
from it gets a cross-origin 3xx back instead of following it. Send
through send to follow those with credentials stripped.
Sourcepub fn request<U: IntoUrl>(&self, method: Method, url: U) -> RequestBuilder
pub fn request<U: IntoUrl>(&self, method: Method, url: U) -> RequestBuilder
Start a request.
Sourcepub fn get<U: IntoUrl>(&self, url: U) -> RequestBuilder
pub fn get<U: IntoUrl>(&self, url: U) -> RequestBuilder
Start a GET.
Sourcepub fn post<U: IntoUrl>(&self, url: U) -> RequestBuilder
pub fn post<U: IntoUrl>(&self, url: U) -> RequestBuilder
Start a POST.
Sourcepub fn put<U: IntoUrl>(&self, url: U) -> RequestBuilder
pub fn put<U: IntoUrl>(&self, url: U) -> RequestBuilder
Start a PUT.
Sourcepub fn delete<U: IntoUrl>(&self, url: U) -> RequestBuilder
pub fn delete<U: IntoUrl>(&self, url: U) -> RequestBuilder
Start a DELETE.
Sourcepub fn head<U: IntoUrl>(&self, url: U) -> RequestBuilder
pub fn head<U: IntoUrl>(&self, url: U) -> RequestBuilder
Start a HEAD.
Sourcepub fn max_response_bytes(&self) -> Option<u64>
pub fn max_response_bytes(&self) -> Option<u64>
The buffered-read limit.
Sourcepub async fn send(
&self,
request: RequestBuilder,
) -> Result<Response, FaucetError>
pub async fn send( &self, request: RequestBuilder, ) -> Result<Response, FaucetError>
Send one attempt and follow its redirects. Any status comes back as a response; only a transport failure is an error.
Sourcepub async fn send_request(
&self,
request: Request,
) -> Result<Response, FaucetError>
pub async fn send_request( &self, request: Request, ) -> Result<Response, FaucetError>
send for an already-built request.
Sourcepub async fn execute<F>(
&self,
ctx: &CallContext,
op: &'static str,
build: F,
) -> Result<Response, FaucetError>where
F: FnMut() -> RequestBuilder,
pub async fn execute<F>(
&self,
ctx: &CallContext,
op: &'static str,
build: F,
) -> Result<Response, FaucetError>where
F: FnMut() -> RequestBuilder,
Run a request as one backend call under ctx (CallContext::call):
build is invoked once per attempt, a non-2xx response is an error
(status_error) so a 5xx / 429 is retried by the context’s
policy, and the 2xx response is returned.
Sourcepub async fn call(
&self,
ctx: &CallContext,
op: &'static str,
request: RequestBuilder,
) -> Result<Response, FaucetError>
pub async fn call( &self, ctx: &CallContext, op: &'static str, request: RequestBuilder, ) -> Result<Response, FaucetError>
Send request as one backend call under ctx and return the response
whatever its status — for a connector that classifies statuses itself.
Attempts are retried under the context’s policy only while the request
can be re-sent; a streamed body goes out once.
Sourcepub async fn bytes(&self, resp: Response) -> Result<Vec<u8>, FaucetError>
pub async fn bytes(&self, resp: Response) -> Result<Vec<u8>, FaucetError>
Read the whole body, refusing one above the read limit.
Sourcepub async fn text(&self, resp: Response) -> Result<String, FaucetError>
pub async fn text(&self, resp: Response) -> Result<String, FaucetError>
Read the whole body as text (invalid UTF-8 replaced).
Sourcepub async fn json<T: DeserializeOwned>(
&self,
resp: Response,
) -> Result<T, FaucetError>
pub async fn json<T: DeserializeOwned>( &self, resp: Response, ) -> Result<T, FaucetError>
Read the whole body as JSON.
Sourcepub async fn json_value(&self, resp: Response) -> Result<Value, FaucetError>
pub async fn json_value(&self, resp: Response) -> Result<Value, FaucetError>
A JSON response body as a Value with exact numbers: a literal the
value would not spell again stays a string of its digits
(crate::fidelity::from_slice).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
impl Freeze for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
Blanket Implementations§
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request