pub struct Client { /* private fields */ }
Expand description
An HTTP client for making requests.
The client maintains a connection pool internally and is expensive to create, so we recommend re-using your clients instead of discarding and recreating them.
Implementations
sourceimpl Client
impl Client
sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Create a new HTTP client using the default configuration.
If the client fails to initialize, an error will be returned.
sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Create a new builder for building a custom client.
sourcepub fn get<U>(&self, uri: U) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
pub fn get<U>(&self, uri: U) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
Sends an HTTP GET request.
The response body is provided as a stream that may only be consumed once.
sourcepub fn head<U>(&self, uri: U) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
pub fn head<U>(&self, uri: U) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
Sends an HTTP HEAD request.
sourcepub fn post<U>(
&self,
uri: U,
body: impl Into<Body>
) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
pub fn post<U>(
&self,
uri: U,
body: impl Into<Body>
) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
Sends an HTTP POST request.
The response body is provided as a stream that may only be consumed once.
sourcepub fn put<U>(
&self,
uri: U,
body: impl Into<Body>
) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
pub fn put<U>(
&self,
uri: U,
body: impl Into<Body>
) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
Sends an HTTP PUT request.
The response body is provided as a stream that may only be consumed once.
sourcepub fn delete<U>(&self, uri: U) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
pub fn delete<U>(&self, uri: U) -> Result<Response<Body>, Error>where
Uri: HttpTryFrom<U>,
Sends an HTTP DELETE request.
The response body is provided as a stream that may only be consumed once.
sourcepub fn send<B: Into<Body>>(
&self,
request: Request<B>
) -> Result<Response<Body>, Error>
pub fn send<B: Into<Body>>(
&self,
request: Request<B>
) -> Result<Response<Body>, Error>
Sends a request and returns the response.
The request may include extensions to customize how it is sent. If the
request contains an Options
struct as an extension, then those options will be used
instead of the default options this client is configured with.
The response body is provided as a stream that may only be consumed once.