2 unstable releases
0.2.0 | May 19, 2024 |
---|---|
0.1.0 | Sep 29, 2023 |
#278 in HTTP client
10,530 downloads per month
5KB
reqwest-leaky-bucket
leaky-bucket
rate-limit middleware implementation for
reqwest-middleware
based on
reqwest-ratelimit
.
Usage
use async_trait::async_trait;
use reqwest_leaky_bucket::leaky_bucket::RateLimiter;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
async fn run() {
let limiter = RateLimiter::builder().max(10).initial(0).refill(5).build();
let client = ClientBuilder::new(reqwest::Client::new())
.with(reqwest_leaky_bucket::rate_limit_all(limiter))
.build();
client.get("https://crates.io").send().await.unwrap();
}
lib.rs
:
Middleware to rate-limit requests built on
reqwest_middleware
,
reqwest_ratelimit
and leaky_bucket
.
Provides a reqwest_ratelimit::RateLimiter
adapter for leaky_bucket::RateLimiter
.
Example
use async_trait::async_trait;
use reqwest_leaky_bucket::leaky_bucket::RateLimiter;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
async fn run() {
let limiter = RateLimiter::builder().max(10).initial(0).refill(5).build();
let client = ClientBuilder::new(reqwest::Client::new())
.with(reqwest_leaky_bucket::rate_limit_all(limiter))
.build();
client.get("https://crates.io").send().await.unwrap();
}
Dependencies
~6–17MB
~224K SLoC