2 unstable releases

0.2.0 May 19, 2024
0.1.0 Sep 29, 2023

#278 in HTTP client

Download history 92/week @ 2024-08-16 114/week @ 2024-08-23 70/week @ 2024-08-30 148/week @ 2024-09-06 98/week @ 2024-09-13 234/week @ 2024-09-20 240/week @ 2024-09-27 1729/week @ 2024-10-04 6097/week @ 2024-10-11 6750/week @ 2024-10-18 5561/week @ 2024-10-25 4825/week @ 2024-11-01 5660/week @ 2024-11-08 1815/week @ 2024-11-15 1240/week @ 2024-11-22 903/week @ 2024-11-29

10,530 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
~224K SLoC