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() -> Client
pub fn new() -> Client
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(&self) -> Option<&(dyn CacheDb + 'static)>
pub fn cache(&self) -> Option<&(dyn CacheDb + 'static)>
Reference the cache used in this client.
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§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§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.