3 releases (breaking)

new 0.3.0 Jan 9, 2025
0.2.0 May 19, 2024
0.1.0 Sep 29, 2023

#213 in HTTP client

Download history 179/week @ 2024-09-19 270/week @ 2024-09-26 861/week @ 2024-10-03 5645/week @ 2024-10-10 6497/week @ 2024-10-17 5956/week @ 2024-10-24 5127/week @ 2024-10-31 6020/week @ 2024-11-07 2145/week @ 2024-11-14 1216/week @ 2024-11-21 1065/week @ 2024-11-28 958/week @ 2024-12-05 934/week @ 2024-12-12 285/week @ 2024-12-19 271/week @ 2024-12-26 427/week @ 2025-01-02

2,179 downloads per month

MIT license

5KB

reqwest-leaky-bucket

leaky-bucket rate-limit middleware implementation for reqwest-middleware based on reqwest-ratelimit.

Crates.io Docs.rs

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–18MB
~229K SLoC