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 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>
Source§impl HttpClient
impl HttpClient
Sourcepub fn py_new(
default_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>,
) -> PyResult<Self>
pub fn py_new( default_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>, ) -> PyResult<Self>
Creates a new HttpClient.
Rate limiting can be configured on a per-endpoint basis by passing key-value pairs of endpoint URLs and their respective quotas.
For /foo -> 10 reqs/sec configure limit with (“foo”, Quota.rate_per_second(10))
Hierarchical rate limiting can be achieved by configuring the quotas for each level.
For /foo/bar -> 10 reqs/sec and /foo -> 20 reqs/sec configure limits for keys “foo/bar” and “foo” respectively.
When a request is made the URL should be split into all the keys within it.
For request /foo/bar, should pass keys [“foo/bar”, “foo”] for rate limiting.
§Errors
- Returns
HttpInvalidProxyErrorif the proxy URL is malformed. - Returns
HttpClientBuildErrorif building the HTTP client fails.
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 moreSource§impl Debug for HttpClient
impl Debug for HttpClient
Source§impl<'py> IntoPyObject<'py> for HttpClient
impl<'py> IntoPyObject<'py> for HttpClient
Source§type Target = HttpClient
type Target = HttpClient
Source§type Output = Bound<'py, <HttpClient as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <HttpClient as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for HttpClient
impl PyClass for HttpClient
Source§impl PyClassImpl for HttpClient
impl PyClassImpl for HttpClient
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// 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.
const RAW_DOC: &'static CStr = /// 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.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<HttpClient>
type ThreadChecker = SendablePyClass<HttpClient>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for HttpClient
impl PyClassNewTextSignature for HttpClient
const TEXT_SIGNATURE: &'static str = "(default_headers=..., header_keys=..., keyed_quotas=..., default_quota=None, timeout_secs=None, proxy_url=None)"
Source§impl PyMethods<HttpClient> for PyClassImplCollector<HttpClient>
impl PyMethods<HttpClient> for PyClassImplCollector<HttpClient>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for HttpClient
impl PyTypeInfo for HttpClient
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for HttpClient
impl ExtractPyClassWithClone for HttpClient
Auto Trait Implementations§
impl Freeze for HttpClient
impl !RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl !UnwindSafe for HttpClient
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,
§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> 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<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read moreSource§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
Source§fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more