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.
# 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()
.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 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.