4 releases (2 breaking)

new 0.3.0 Jan 9, 2025
0.2.0 May 4, 2024
0.1.1 Sep 28, 2023
0.1.0 Sep 28, 2023

#419 in HTTP client

Download history 284/week @ 2024-09-22 295/week @ 2024-09-29 2885/week @ 2024-10-06 5903/week @ 2024-10-13 6915/week @ 2024-10-20 5451/week @ 2024-10-27 4829/week @ 2024-11-03 5229/week @ 2024-11-10 1350/week @ 2024-11-17 1254/week @ 2024-11-24 812/week @ 2024-12-01 1272/week @ 2024-12-08 693/week @ 2024-12-15 118/week @ 2024-12-22 371/week @ 2024-12-29 775/week @ 2025-01-05

2,040 downloads per month
Used in reqwest-leaky-bucket

MIT license

5KB

reqwest-ratelimit

Rate-limit middleware implementation for reqwest-middleware.

Crates.io Docs.rs

Usage

use async_trait::async_trait;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};

struct RateLimiter;

#[async_trait]
impl reqwest_ratelimit::RateLimiter for RateLimiter {
    async fn acquire_permit(&self) {
        // noop
    }
}

async fn run() {
    let client = ClientBuilder::new(reqwest::Client::new())
        .with(reqwest_ratelimit::all(RateLimiter))
        .build();

    client.get("https://crates.io").send().await.unwrap();
}

lib.rs:

Middleware to rate-limit requests built on reqwest_middleware.

You're exected to provide your own RateLimiter implementation.

Example

use async_trait::async_trait;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};

struct RateLimiter;

#[async_trait]
impl reqwest_ratelimit::RateLimiter for RateLimiter {
    async fn acquire_permit(&self) {
        // noop
    }
}

async fn run() {
    let client = ClientBuilder::new(reqwest::Client::new())
        .with(reqwest_ratelimit::all(RateLimiter))
        .build();

    client.get("https://crates.io").send().await.unwrap();
}

Dependencies

~4–15MB
~190K SLoC