pub struct Client<C, B = Body> { /* private fields */ }
Expand description
A Client to make outgoing HTTP requests.
Implementations
sourceimpl 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.
sourceimpl<C, B> Client<C, B> where
C: Connect + Clone + Send + Sync + 'static,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
impl<C, B> Client<C, B> where
C: Connect + Clone + Send + Sync + 'static,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
sourcepub fn get(&self, uri: Uri) -> ResponseFutureⓘNotable traits for ResponseFutureimpl Future for ResponseFuture type Output = Result<Response<Body>>;
where
B: Default,
pub fn get(&self, uri: Uri) -> ResponseFutureⓘNotable traits for ResponseFutureimpl Future for ResponseFuture type Output = Result<Response<Body>>;
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ⓘNotable traits for ResponseFutureimpl Future for ResponseFuture type Output = Result<Response<Body>>;
pub fn request(&self, req: Request<B>) -> ResponseFutureⓘNotable traits for ResponseFutureimpl Future for ResponseFuture type Output = Result<Response<Body>>;
Send a constructed Request
using this Client
.
Example
use hyper::{Body, Client, Request};
let client = Client::new();
let req = Request::builder()
.method("POST")
.uri("http://httpin.org/post")
.body(Body::from("Hallo!"))
.expect("request builder");
let future = client.request(req);
Trait Implementations
sourceimpl Default for Client<HttpConnector, Body>
impl Default for Client<HttpConnector, Body>
sourceimpl<C, B> Service<Request<B>> for Client<C, B> where
C: Connect + Clone + Send + Sync + 'static,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
impl<C, B> Service<Request<B>> for Client<C, B> where
C: Connect + Clone + Send + Sync + 'static,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
type Future = ResponseFuture
type Future = ResponseFuture
The future response value.
sourceimpl<C, B> Service<Request<B>> for &Client<C, B> where
C: Connect + Clone + Send + Sync + 'static,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
impl<C, B> Service<Request<B>> for &Client<C, B> where
C: Connect + Clone + Send + Sync + 'static,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
type Future = ResponseFuture
type Future = ResponseFuture
The future response value.
Auto Trait Implementations
impl<C, B = Body> !RefUnwindSafe for Client<C, B>
impl<C, B> Send for Client<C, B> where
B: Send,
C: Send,
impl<C, B> Sync for Client<C, B> where
B: Send,
C: Sync,
impl<C, B> Unpin for Client<C, B> where
C: Unpin,
impl<C, B = Body> !UnwindSafe for Client<C, B>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more