2 unstable releases

0.2.0 May 19, 2024
0.1.0 Sep 29, 2023

#305 in HTTP client

Download history 132/week @ 2024-06-04 122/week @ 2024-06-11 84/week @ 2024-06-18 90/week @ 2024-06-25 98/week @ 2024-07-02 91/week @ 2024-07-09 131/week @ 2024-07-16 88/week @ 2024-07-23 102/week @ 2024-07-30 71/week @ 2024-08-06 77/week @ 2024-08-13 127/week @ 2024-08-20 84/week @ 2024-08-27 81/week @ 2024-09-03 164/week @ 2024-09-10 68/week @ 2024-09-17

410 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–17MB
~231K SLoC