pub struct Client<C, B = Body> {
config: Config,
conn_builder: Builder,
connector: C,
pool: Pool<PoolClient<B>>,
}
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.
Fields§
§config: Config
§conn_builder: Builder
§connector: C
§pool: Pool<PoolClient<B>>
Implementations§
source§impl Client<HttpConnector, Body>
impl Client<HttpConnector, Body>
sourcepub fn new() -> Client<HttpConnector, Body>
pub fn new() -> Client<HttpConnector, Body>
Create a new Client with the default config.
§Note
The default connector does not handle TLS. Speaking to https
destinations will require configuring a connector that implements
TLS.
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 HttpBody
type have a Default
implementation.
It should return an “empty” version of itself, such that
HttpBody::is_end_stream
is true
.
§Example
use hyper::{Client, Uri};
let client = Client::new();
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::{Body, Method, Client, Request};
let client = Client::new();
let req = Request::builder()
.method(Method::POST)
.uri("http://httpbin.org/post")
.body(Body::from("Hallo!"))
.expect("request builder");
let future = client.request(req);
async fn retryably_send_request( self, req: Request<B>, pool_key: (Scheme, Authority), ) -> Result<Response<Body>>
async fn send_request( &self, req: Request<B>, pool_key: (Scheme, Authority), ) -> Result<Response<Body>, ClientError<B>>
async fn connection_for( &self, pool_key: (Scheme, Authority), ) -> Result<Pooled<PoolClient<B>>, ClientConnectError>
fn connect_to( &self, pool_key: (Scheme, Authority), ) -> impl Lazy<Output = Result<Pooled<PoolClient<B>>>> + Unpin
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 = Body> !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 = Body> !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