Crate reqwest_leaky_bucket

source ·
Expand description

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();
}

Re-exports§

Structs§

Functions§

Type Aliases§