3 unstable releases

0.2.0 May 4, 2024
0.1.1 Sep 28, 2023
0.1.0 Sep 28, 2023

#511 in HTTP client

Download history 84/week @ 2024-07-20 129/week @ 2024-07-27 74/week @ 2024-08-03 82/week @ 2024-08-10 111/week @ 2024-08-17 215/week @ 2024-08-24 90/week @ 2024-08-31 160/week @ 2024-09-07 106/week @ 2024-09-14 280/week @ 2024-09-21 253/week @ 2024-09-28 2636/week @ 2024-10-05 5890/week @ 2024-10-12 6901/week @ 2024-10-19 5509/week @ 2024-10-26 4039/week @ 2024-11-02

23,298 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
~188K SLoC