Expand description
Rate limiting helpers and optional wrapper ergonomics for reqwest.
This crate keeps reqwest at the center while adding helpers to apply rate limits
and, optionally, a small wrapper client with middleware hooks.
§Example
use governor::Quota;
use std::num::NonZeroU32;
use std::sync::Arc;
let rate_limiter = Arc::new(governor::RateLimiter::direct(Quota::per_hour(
NonZeroU32::new(5_000).unwrap(),
)));
let client = reqwest_rate_limit::Client::builder()
.user_agent("reqwest-rate-limit-docs")
.configure(|b| b.timeout(std::time::Duration::from_secs(30)))
.build()
.unwrap();
let _future = client
.get("https://api.example.com/v1/health")
.with_rate_limiter(rate_limiter)
.send();§Why configure?
ClientBuilder::configure gives you access to the full surface of
reqwest::ClientBuilder without this crate having to mirror every method.
That means you can use all of reqwest’s options and still keep the wrapper
ergonomics and middleware hooks.
let client = reqwest_rate_limit::Client::builder()
.configure(|b| {
b.timeout(std::time::Duration::from_secs(10))
.pool_max_idle_per_host(8)
.https_only(true)
})
.rate_limiter(rate_limiter)
.build()
.unwrap();If you do not want the wrapper, use send_with_rate_limiter with a plain
reqwest::Client instead.
§ResponseMiddleware
Implement ResponseMiddleware to inspect responses and apply rate-limit rules.
The github_rest_api.rs example shows how to translate
retry-after headers into concrete waits and backoff behavior.
§Features
This crate forwards optional reqwest features:
json, form, query, and multipart.
Re-exports§
pub use reqwest_wrapper::Client;pub use reqwest_wrapper::ClientBuilder;pub use reqwest_wrapper::RequestBuilder;pub use governor;
Modules§
Structs§
- Noop
Response Middleware - Default middleware that returns the response unchanged.
Traits§
- Response
Middleware - Intercept a response to apply rate-limit aware behavior.
Functions§
- send_
with_ rate_ limiter - Send a request after waiting for the rate limiter to allow it.
- send_
with_ rate_ limiter_ and_ middleware - Send a request through a response middleware after rate limiting.