pub struct Client<C = HttpConnector> { /* private fields */ }Expand description
HTTP client with connection pooling, redirect handling, and retry support.
The default type parameter C = HttpConnector gives a plain HTTP-only
client. Use HttpsClient (feature tls) for a TLS-capable client.
Created via Client::builder().build() or Client::builder().build_https().
Implementations§
Source§impl Client<HttpConnector>
Provide builder() only on the default Client<HttpConnector> variant so
that type-inference works without annotation at call sites.
impl Client<HttpConnector>
Provide builder() only on the default Client<HttpConnector> variant so
that type-inference works without annotation at call sites.
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Return a ClientBuilder for configuring a new client.
Source§impl<C> Client<C>
impl<C> Client<C>
Sourcepub fn get(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
pub fn get(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
Build a GET request for the given URL.
Sourcepub fn post(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
pub fn post(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
Build a POST request for the given URL.
Sourcepub fn put(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
pub fn put(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
Build a PUT request for the given URL.
Sourcepub fn delete(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
pub fn delete(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
Build a DELETE request for the given URL.
Sourcepub fn patch(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
pub fn patch(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
Build a PATCH request for the given URL.
Sourcepub fn head(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
pub fn head(&self, url: &str) -> Result<RequestBuilder<C>, OxiHttpError>
Build a HEAD request for the given URL.
Sourcepub async fn execute(
&self,
req: Request<Full<Bytes>>,
) -> Result<Response, OxiHttpError>
pub async fn execute( &self, req: Request<Full<Bytes>>, ) -> Result<Response, OxiHttpError>
Execute a pre-built http::Request.
Sourcepub async fn get_bytes(&self, url: &str) -> Result<Bytes, OxiHttpError>
pub async fn get_bytes(&self, url: &str) -> Result<Bytes, OxiHttpError>
Convenience: GET the URL and return the response body as bytes.
Sourcepub async fn get_json<T: DeserializeOwned>(
&self,
url: &str,
) -> Result<T, OxiHttpError>
pub async fn get_json<T: DeserializeOwned>( &self, url: &str, ) -> Result<T, OxiHttpError>
Convenience: GET the URL and deserialize the JSON response body.
Sourcepub async fn post_json<T: Serialize, R: DeserializeOwned>(
&self,
url: &str,
body: &T,
) -> Result<R, OxiHttpError>
pub async fn post_json<T: Serialize, R: DeserializeOwned>( &self, url: &str, body: &T, ) -> Result<R, OxiHttpError>
Convenience: POST JSON and deserialize the response.
Sourcepub fn retry_policy(&self) -> Option<&RetryPolicy>
pub fn retry_policy(&self) -> Option<&RetryPolicy>
Returns a reference to the retry policy, if configured.
Sourcepub fn connect_timeout(&self) -> Option<Duration>
pub fn connect_timeout(&self) -> Option<Duration>
Returns a reference to the connect timeout, if set.
Sourcepub fn read_timeout(&self) -> Option<Duration>
pub fn read_timeout(&self) -> Option<Duration>
Returns a reference to the read timeout, if set.