pub struct HttpClient { /* private fields */ }Expand description
An asynchronous HTTP client with rate limiting, timeouts, and custom headers.
The client uses reqwest for I/O and supports default and per-key quotas. Multiple clients
can share the same rate limiter when their requests consume one quota budget.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub async fn request(
&self,
method: Method,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request( &self, method: Method, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn request_with_url_redacted(
&self,
method: Method,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_url_redacted( &self, method: Method, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request while redacting the URL from logs and transport errors.
Use this for endpoints whose path or other URL components can carry credentials.
§Errors
Returns an error if unable to send request or times out.
Sourcepub async fn request_with_params<P: Serialize>(
&self,
method: Method,
url: String,
params: Option<&P>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_params<P: Serialize>( &self, method: Method, url: String, params: Option<&P>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request with serializable query parameters.
This method accepts any type implementing Serialize for query parameters,
which will be automatically encoded into the URL query string using reqwest’s
.query() method, avoiding unnecessary HashMap allocations.
§Errors
Returns an error if unable to send request or times out.
Sourcepub async fn request_with_ustr_keys(
&self,
method: Method,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<Ustr>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_ustr_keys( &self, method: Method, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<Ustr>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request using pre-interned rate limiter keys.
§Errors
Returns an error if unable to send the request or the request times out.
Sourcepub async fn get(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn get( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn post(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn post( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn patch(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn patch( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn delete(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn delete( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub fn builder() -> HttpClientBuilder
pub fn builder() -> HttpClientBuilder
Returns a builder for a new HttpClient instance.
Set rate_limiters to share quota state across clients. When omitted, the client creates
one rate limiter from default_quota and keyed_quotas. An explicit empty vector disables
rate limiting. Each request awaits every configured limiter with the same keys. A limiter
without a default quota ignores keys it does not own, allowing independent scopes such as
per-IP and per-account limits to apply to one request.
§Errors
Returns an error if:
- Shared rate limiters are combined with quota configuration.
- The proxy URL is malformed.
- Building the underlying
reqwest::Clientfails.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more