pub struct HttpClient { /* private fields */ }Expand description
Represents a client to use for making HTTP requests.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new_with_cache(cache_dir: impl AsRef<Path>) -> Self
pub fn new_with_cache(cache_dir: impl AsRef<Path>) -> Self
Constructs a new HTTP client using the given cache directory.
Sourcepub fn from_existing(client: Client) -> Self
pub fn from_existing(client: Client) -> Self
Constructs a new HTTP client using an existing client.
Sourcepub fn from_existing_with_cache(
client: Client,
cache_dir: impl AsRef<Path>,
) -> Self
pub fn from_existing_with_cache( client: Client, cache_dir: impl AsRef<Path>, ) -> Self
Constructs a new HTTP client using an existing client and the given cache directory.
Sourcepub fn cache(&self) -> Option<&Cache<DefaultCacheStorage>>
pub fn cache(&self) -> Option<&Cache<DefaultCacheStorage>>
Gets the associated cache.
If None, the client is not configured for caching.
Methods from Deref<Target = ClientWithMiddleware>§
Sourcepub fn get<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn get<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a GET request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn post<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn post<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a POST request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn put<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn put<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a PUT request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn patch<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn patch<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a PATCH request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn delete<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn delete<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a DELETE request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn head<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn head<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a HEAD request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn request<U>(&self, method: Method, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn request<U>(&self, method: Method, url: U) -> RequestBuilderwhere
U: IntoUrl,
Start building a Request with the Method and Url.
Returns a RequestBuilder, which will allow setting headers and
the request body before sending.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub async fn execute(&self, req: Request) -> Result<Response, Error>
pub async fn execute(&self, req: Request) -> Result<Response, Error>
Executes a Request.
A Request can be built manually with Request::new() or obtained
from a RequestBuilder with RequestBuilder::build().
You should prefer to use the RequestBuilder and
RequestBuilder::send().
§Errors
This method fails if there was an error while sending request, redirect loop was detected or redirect limit was exhausted.
Sourcepub async fn execute_with_extensions(
&self,
req: Request,
ext: &mut Extensions,
) -> Result<Response, Error>
pub async fn execute_with_extensions( &self, req: Request, ext: &mut Extensions, ) -> Result<Response, Error>
Executes a Request with initial Extensions.
A Request can be built manually with Request::new() or obtained
from a RequestBuilder with RequestBuilder::build().
You should prefer to use the RequestBuilder and
RequestBuilder::send().
§Errors
This method fails if there was an error while sending request, redirect loop was detected or redirect limit was exhausted.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more