Struct Client

struct Client { ... }

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

Constructs 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 an Error instead of panicking.

fn builder() -> ClientBuilder

Creates a ClientBuilder to configure a Client.

This is the same as ClientBuilder::new().

fn get<U: IntoUrl>(self: &Self, url: U) -> RequestBuilder

Convenience method to make a GET request to a URL.

Errors

This method fails whenever the supplied Url cannot be parsed.

fn post<U: IntoUrl>(self: &Self, url: U) -> RequestBuilder

Convenience method to make a POST request to a URL.

Errors

This method fails whenever the supplied Url cannot be parsed.

fn put<U: IntoUrl>(self: &Self, url: U) -> RequestBuilder

Convenience method to make a PUT request to a URL.

Errors

This method fails whenever the supplied Url cannot be parsed.

fn patch<U: IntoUrl>(self: &Self, url: U) -> RequestBuilder

Convenience method to make a PATCH request to a URL.

Errors

This method fails whenever the supplied Url cannot be parsed.

fn delete<U: IntoUrl>(self: &Self, url: U) -> RequestBuilder

Convenience method to make a DELETE request to a URL.

Errors

This method fails whenever the supplied Url cannot be parsed.

fn head<U: IntoUrl>(self: &Self, url: U) -> RequestBuilder

Convenience method to make a HEAD request to a URL.

Errors

This method fails whenever the supplied Url cannot be parsed.

fn request<U: IntoUrl>(self: &Self, method: Method, url: U) -> RequestBuilder

Start building a Request with the Method and Url.

Returns a RequestBuilder, which will allow setting headers and the request body before sending.

Errors

This method fails whenever the supplied Url cannot be parsed.

fn execute(self: &Self, request: Request) -> impl Future<Output = Result<Response, Error>>

Executes a Request.

A Request can be built manually with Request::new() or obtained from a RequestBuilder with RequestBuilder::build().

You should prefer to use the RequestBuilder and RequestBuilder::send().

Errors

This method fails if there was an error while sending request, redirect loop was detected or redirect limit was exhausted.

impl Clone for Client

fn clone(self: &Self) -> Client

impl Debug for Client

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

impl Default for Client

fn default() -> Self

impl Freeze for Client

impl RefUnwindSafe for Client

impl Send for Client

impl Service for Client

fn poll_ready(self: &mut Self, _cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>
fn call(self: &mut Self, req: Request) -> <Self as >::Future

impl Sync for Client

impl Unpin for Client

impl UnsafeUnpin for Client

impl UnwindSafe for Client

impl<T> Any for Client

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Client

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Client

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

impl<T> CloneToUninit for Client

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

impl<T> ErasedDestructor for Client

impl<T> From for Client

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Client

impl<T> PolicyExt for Client

fn and<P, B, E>(self: Self, other: P) -> And<T, P>
where
    T: Policy<B, E>,
    P: Policy<B, E>
fn or<P, B, E>(self: Self, other: P) -> Or<T, P>
where
    T: Policy<B, E>,
    P: Policy<B, E>

impl<T> ToOwned for Client

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> WithSubscriber for Client

impl<T, Request> ServiceExt for Client

impl<T, U> Into for Client

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Client

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

impl<T, U> TryInto for Client

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