pub struct Client { /* private fields */ }
Expand description
HTTP client.
An HTTP client acts as a session for executing one of more HTTP requests.
Implementations§
source§impl Client
impl Client
sourcepub fn new() -> Self
pub fn new() -> Self
New client with default config.
This enables cookies, sets the redirect_policy
with a limit of up-to 20 redirects and auto_referer
, sets
the connect_timeout
to 90 seconds and enables metrics
.
sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Start a new ClientBuilder
for creating a custom client.
Gets the configured cookie-jar for this client, if cookies are enabled.
sourcepub async fn get(&self, uri: impl TryUri) -> Result<Response, Error>
pub async fn get(&self, uri: impl TryUri) -> Result<Response, Error>
Send a GET request to the uri
.
sourcepub async fn get_txt(&self, uri: impl TryUri) -> Result<Txt, Error>
pub async fn get_txt(&self, uri: impl TryUri) -> Result<Txt, Error>
Send a GET request to the uri
and read the response as a string.
sourcepub async fn get_bytes(&self, uri: impl TryUri) -> Result<Vec<u8>, Error>
pub async fn get_bytes(&self, uri: impl TryUri) -> Result<Vec<u8>, Error>
Send a GET request to the uri
and read the response as raw bytes.
sourcepub async fn get_json<O>(&self, uri: impl TryUri) -> Result<O, Box<dyn Error>>where
O: DeserializeOwned + Unpin,
pub async fn get_json<O>(&self, uri: impl TryUri) -> Result<O, Box<dyn Error>>where
O: DeserializeOwned + Unpin,
Send a GET request to the uri
and de-serializes the response.
sourcepub async fn head(&self, uri: impl TryUri) -> Result<Response, Error>
pub async fn head(&self, uri: impl TryUri) -> Result<Response, Error>
Send a HEAD request to the uri
.
sourcepub async fn put(
&self,
uri: impl TryUri,
body: impl TryBody,
) -> Result<Response, Error>
pub async fn put( &self, uri: impl TryUri, body: impl TryBody, ) -> Result<Response, Error>
Send a PUT request to the uri
with a given request body.
sourcepub async fn post(
&self,
uri: impl TryUri,
body: impl TryBody,
) -> Result<Response, Error>
pub async fn post( &self, uri: impl TryUri, body: impl TryBody, ) -> Result<Response, Error>
Send a POST request to the uri
with a given request body.
sourcepub async fn delete(&self, uri: impl TryUri) -> Result<Response, Error>
pub async fn delete(&self, uri: impl TryUri) -> Result<Response, Error>
Send a DELETE request to the uri
.
sourcepub async fn send(&self, request: Request) -> Result<Response, Error>
pub async fn send(&self, request: Request) -> Result<Response, Error>
Send a custom Request
.
§Cache
If the client has a cache
and the request uses the GET
method the result will be cached
according with the cache_mode
selected for the request.
sourcepub fn cache_mode(&self, request: &Request) -> CacheMode
pub fn cache_mode(&self, request: &Request) -> CacheMode
Returns the CacheMode
that is used in this client if the request is made.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more