2 unstable releases

0.2.0 May 19, 2024
0.1.0 Sep 29, 2023

#284 in HTTP client

Download history 96/week @ 2024-07-24 94/week @ 2024-07-31 76/week @ 2024-08-07 75/week @ 2024-08-14 124/week @ 2024-08-21 82/week @ 2024-08-28 86/week @ 2024-09-04 156/week @ 2024-09-11 126/week @ 2024-09-18 309/week @ 2024-09-25 655/week @ 2024-10-02 4909/week @ 2024-10-09 5915/week @ 2024-10-16 6251/week @ 2024-10-23 5585/week @ 2024-10-30 4210/week @ 2024-11-06

22,857 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

~7–17MB
~225K SLoC