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,
§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