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>,
) -> Self
pub fn new( headers: HashMap<String, String>, header_keys: Vec<String>, keyed_quotas: Vec<(String, Quota)>, default_quota: Option<Quota>, ) -> Self
Creates a new HttpClient
instance.
Sourcepub async fn request(
&self,
method: Method,
url: String,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
keys: Option<Vec<String>>,
timeout_secs: Option<u64>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request( &self, method: Method, url: String, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, keys: Option<Vec<String>>, timeout_secs: Option<u64>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request.
method
: The [Method
] to use (GET, POST, etc.).url
: The target URL.headers
: Additional headers for this request.body
: Optional request body.keys
: Rate-limit keys to control request frequency.timeout_secs
: Optional request timeout in seconds.
§Errors
Returns an error if unable to send request or times out.
§Examples
If requesting /foo/bar
, pass rate-limit keys ["foo/bar", "foo"]
.
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>,
) -> Self
pub fn py_new( default_headers: HashMap<String, String>, header_keys: Vec<String>, keyed_quotas: Vec<(String, Quota)>, default_quota: Option<Quota>, ) -> Self
Creates a new HttpClient.
default_headers
: The default headers to be used with every request.
header_keys
: The key value pairs for the given header_keys
are retained from the responses.
keyed_quota
: A list of string quota pairs that gives quota for specific key values.
default_quota
: The default rate limiting quota for any request.
Default quota is optional and no quota is passthrough.
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.
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 IntoPy<Py<PyAny>> for HttpClient
impl IntoPy<Py<PyAny>> 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§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<HttpClient> for PyClassImplCollector<HttpClient>
impl PyClassNewTextSignature<HttpClient> for PyClassImplCollector<HttpClient>
fn new_text_signature(self) -> Option<&'static str>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a HttpClient
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a HttpClient
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut HttpClient
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut HttpClient
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 type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
PyTypeInfo::type_object
PyTypeInfo::type_object
].§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_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_type_of
PyTypeInfo::is_type_of
].§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.§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_exact_type_of
PyTypeInfo::is_exact_type_of
].impl DerefToPyAny 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> FromPyObject<'_> for Twhere
T: PyClass + Clone,
impl<T> FromPyObject<'_> for Twhere
T: PyClass + Clone,
§fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
§fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
§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>
§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 more