Struct Client

struct Client<C, B> { ... }

A Client to make outgoing HTTP requests.

Client is cheap to clone and cloning is the recommended way to share a Client. The underlying connection pool will be reused.

Implementations

impl Client<(), ()>

fn builder<E>(executor: E) -> Builder
where
    E: Executor<Pin<Box<dyn Future<Output = ()> + Send>>> + Send + Sync + Clone + 'static

Create a builder to configure a new Client.

Example

# #[cfg(feature = "tokio")]
# fn run () {
use std::time::Duration;
use hyper_util::client::legacy::Client;
use hyper_util::rt::{TokioExecutor, TokioTimer};

let client = Client::builder(TokioExecutor::new())
    .pool_timer(TokioTimer::new())
    .pool_idle_timeout(Duration::from_secs(30))
    .http2_only(true)
    .build_http();
# let infer: Client<_, http_body_util::Full<bytes::Bytes>> = client;
# drop(infer);
# }
# fn main() {}

impl<C, B> Client<C, B>

fn get(self: &Self, uri: Uri) -> ResponseFuture
where
    B: Default

Send a GET request to the supplied Uri.

Note

This requires that the Body type have a Default implementation. It should return an "empty" version of itself, such that Body::is_end_stream is true.

Example

# #[cfg(feature = "tokio")]
# fn run () {
use hyper::Uri;
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;
use bytes::Bytes;
use http_body_util::Full;

let client: Client<_, Full<Bytes>> = Client::builder(TokioExecutor::new()).build_http();

let future = client.get(Uri::from_static("http://httpbin.org/ip"));
# }
# fn main() {}
fn request(self: &Self, req: Request<B>) -> ResponseFuture

Send a constructed Request using this Client.

Example

# #[cfg(feature = "tokio")]
# fn run () {
use hyper::{Method, Request};
use hyper_util::client::legacy::Client;
use http_body_util::Full;
use hyper_util::rt::TokioExecutor;
use bytes::Bytes;

let client: Client<_, Full<Bytes>> = Client::builder(TokioExecutor::new()).build_http();

let req: Request<Full<Bytes>> = Request::builder()
    .method(Method::POST)
    .uri("http://httpbin.org/post")
    .body(Full::from("Hallo!"))
    .expect("request builder");

let future = client.request(req);
# }
# fn main() {}

impl<C, B> Debug for Client<C, B>

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

impl<C, B> Freeze for Client<C, B>

impl<C, B> RefUnwindSafe for Client<C, B>

impl<C, B> Send for Client<C, B>

impl<C, B> Service for Client<C, B>

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

impl<C, B> Sync for Client<C, B>

impl<C, B> Unpin for Client<C, B>

impl<C, B> UnsafeUnpin for Client<C, B>

impl<C, B> UnwindSafe for Client<C, B>

impl<C: Clone, B> Clone for Client<C, B>

fn clone(self: &Self) -> Client<C, B>

impl<T> Any for Client<C, B>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Client<C, B>

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

impl<T> BorrowMut for Client<C, B>

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

impl<T> CloneToUninit for Client<C, B>

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

impl<T> From for Client<C, B>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Client<C, B>

impl<T> ToOwned for Client<C, B>

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

impl<T> WithSubscriber for Client<C, B>

impl<T, U> Into for Client<C, B>

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<C, B>

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

impl<T, U> TryInto for Client<C, B>

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