pub struct Client<C, B> { /* private fields */ }
Available on crate feature
client
and crate feature client-legacy
and (crate features http1
or http2
) only.Expand description
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§
Source§impl Client<(), ()>
impl Client<(), ()>
Sourcepub fn builder<E>(executor: E) -> Builder
pub fn builder<E>(executor: E) -> Builder
Create a builder to configure a new Client
.
§Example
use std::time::Duration;
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;
let client = Client::builder(TokioExecutor::new())
.pool_idle_timeout(Duration::from_secs(30))
.http2_only(true)
.build_http();
Source§impl<C, B> Client<C, B>
impl<C, B> Client<C, B>
Sourcepub fn get(&self, uri: Uri) -> ResponseFuture ⓘwhere
B: Default,
pub fn get(&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
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"));
Sourcepub fn request(&self, req: Request<B>) -> ResponseFuture ⓘ
pub fn request(&self, req: Request<B>) -> ResponseFuture ⓘ
Send a constructed Request
using this Client
.
§Example
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);
Trait Implementations§
Source§impl<C, B> Service<Request<B>> for &Client<C, B>
impl<C, B> Service<Request<B>> for &Client<C, B>
Auto Trait Implementations§
impl<C, B> Freeze for Client<C, B>where
C: Freeze,
impl<C, B> !RefUnwindSafe for Client<C, B>
impl<C, B> Send for Client<C, B>
impl<C, B> Sync for Client<C, B>
impl<C, B> Unpin for Client<C, B>where
C: Unpin,
impl<C, B> !UnwindSafe for Client<C, B>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.