3 unstable releases
0.2.0 | May 4, 2024 |
---|---|
0.1.1 | Sep 28, 2023 |
0.1.0 | Sep 28, 2023 |
#511 in HTTP client
23,298 downloads per month
Used in reqwest-leaky-bucket
5KB
reqwest-ratelimit
Rate-limit middleware implementation for
reqwest-middleware
.
Usage
use async_trait::async_trait;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
struct RateLimiter;
#[async_trait]
impl reqwest_ratelimit::RateLimiter for RateLimiter {
async fn acquire_permit(&self) {
// noop
}
}
async fn run() {
let client = ClientBuilder::new(reqwest::Client::new())
.with(reqwest_ratelimit::all(RateLimiter))
.build();
client.get("https://crates.io").send().await.unwrap();
}
lib.rs
:
Middleware to rate-limit requests built on reqwest_middleware
.
You're exected to provide your own RateLimiter
implementation.
Example
use async_trait::async_trait;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
struct RateLimiter;
#[async_trait]
impl reqwest_ratelimit::RateLimiter for RateLimiter {
async fn acquire_permit(&self) {
// noop
}
}
async fn run() {
let client = ClientBuilder::new(reqwest::Client::new())
.with(reqwest_ratelimit::all(RateLimiter))
.build();
client.get("https://crates.io").send().await.unwrap();
}
Dependencies
~4–15MB
~188K SLoC