pub struct HttpClient { /* private fields */ }Expand description
An HTTP client that supports rate limiting and timeouts.
Built on reqwest for async I/O. Allows per-endpoint and default quotas
through a rate limiter.
This struct is designed to handle HTTP requests efficiently, providing
support for rate limiting, timeouts, and custom headers. The client is
built on top of reqwest and can be used for both synchronous and
asynchronous HTTP requests.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(
headers: HashMap<String, String>,
header_keys: Vec<String>,
keyed_quotas: Vec<(String, Quota)>,
default_quota: Option<Quota>,
timeout_secs: Option<u64>,
proxy_url: Option<String>,
) -> Result<Self, HttpClientError>
pub fn new( headers: HashMap<String, String>, header_keys: Vec<String>, keyed_quotas: Vec<(String, Quota)>, default_quota: Option<Quota>, timeout_secs: Option<u64>, proxy_url: Option<String>, ) -> Result<Self, HttpClientError>
Creates a new HttpClient instance.
§Errors
- Returns
InvalidProxyif the proxy URL is malformed. - Returns
ClientBuildErrorif building the underlyingreqwest::Clientfails.
Sourcepub fn new_with_rate_limiter(
headers: HashMap<String, String>,
header_keys: Vec<String>,
timeout_secs: Option<u64>,
proxy_url: Option<String>,
rate_limiter: Arc<RateLimiter<Ustr, MonotonicClock>>,
) -> Result<Self, HttpClientError>
pub fn new_with_rate_limiter( headers: HashMap<String, String>, header_keys: Vec<String>, timeout_secs: Option<u64>, proxy_url: Option<String>, rate_limiter: Arc<RateLimiter<Ustr, MonotonicClock>>, ) -> Result<Self, HttpClientError>
Creates a new HttpClient instance sharing an externally-owned rate limiter.
Use this constructor to share a single RateLimiter across multiple
HttpClient instances (for example, the HTTP clients owned by an
exchange adapter’s data and execution clients). All quota state lives
inside the limiter, so passing the same Arc produces a single shared
bucket.
§Errors
- Returns
InvalidProxyif the proxy URL is malformed. - Returns
ClientBuildErrorif building the underlyingreqwest::Clientfails.
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_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>
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