Struct Client
pub struct Client { /* private fields */ }
An asynchronous Client to make Requests with.
The Client has various configuration values to tweak, but the defaults
are set to what is usually the most commonly desired value. To configure a
Client, use Client::builder().
The Client holds a connection pool internally to improve performance
by reusing connections and avoiding setup overhead, so it is advised that
you create one and reuse it.
You do not have to wrap the Client in an Rc or Arc to reuse it,
because it already uses an Arc internally.
Connection Pooling
The connection pool can be configured using ClientBuilder methods
with the pool_ prefix, such as ClientBuilder::pool_idle_timeout
and ClientBuilder::pool_max_idle_per_host.
Implementations
impl Client
fn new() -> ClientConstructs a new
Client.Panics
This method panics if a TLS backend cannot be initialized, or the resolver cannot load the system configuration.
Use
Client::builder()if you wish to handle the failure as anErrorinstead of panicking.fn builder() -> ClientBuilderCreates a
ClientBuilderto configure aClient.This is the same as
ClientBuilder::new().fn get<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
GETrequest to a URL.Errors
This method fails whenever the supplied
Urlcannot be parsed.fn post<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
POSTrequest to a URL.Errors
This method fails whenever the supplied
Urlcannot be parsed.fn put<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
PUTrequest to a URL.Errors
This method fails whenever the supplied
Urlcannot be parsed.fn patch<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
PATCHrequest to a URL.Errors
This method fails whenever the supplied
Urlcannot be parsed.fn delete<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
DELETErequest to a URL.Errors
This method fails whenever the supplied
Urlcannot be parsed.fn head<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
HEADrequest to a URL.Errors
This method fails whenever the supplied
Urlcannot be parsed.fn request<U: IntoUrl>(&self, method: Method, url: U) -> RequestBuilderStart building a
Requestwith theMethodandUrl.Returns a
RequestBuilder, which will allow setting headers and the request body before sending.Errors
This method fails whenever the supplied
Urlcannot be parsed.fn execute(&self, request: Request) -> impl Future<Output = Result<Response, Error>>Executes a
Request.A
Requestcan be built manually withRequest::new()or obtained from a RequestBuilder withRequestBuilder::build().You should prefer to use the
RequestBuilderandRequestBuilder::send().Errors
This method fails if there was an error while sending request, redirect loop was detected or redirect limit was exhausted.
Trait Implementations
impl Clone for Client
fn clone(&self) -> Self
impl Debug for Client
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for Client
fn default() -> Self
impl Service<Request> for Client
type Response = Response;type Error = Error;type Future = Pending;fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn call(&mut self, req: Request) -> Self::Future
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
impl<T> Any for Client
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Client
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Client
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Client
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Client
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for Client
impl<T> PolicyExt for Client
where
T: ?Sized,
fn and<P, B, E>(self, other: P) -> And<T, P> where T: Sized + Policy<B, E>, P: Policy<B, E>,fn or<P, B, E>(self, other: P) -> Or<T, P> where T: Sized + Policy<B, E>, P: Policy<B, E>,
impl<T> ToOwned for Client
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> WithSubscriber for Client
impl<T, Request> ServiceExt<Request> for Client
where
T: Service<Request> + ?Sized,
impl<T, U> Into<U> for Client
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Client
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Client
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>