surf-governor

A rate-limiting middleware for surf

5 releases

0.2.0 Jul 14, 2023
0.1.3 Feb 18, 2023
0.1.2 Nov 17, 2022
0.1.1 Jun 17, 2022
0.1.0 May 22, 2022

#392 in HTTP client

Download history 15/week @ 2024-06-17 12/week @ 2024-06-24 4/week @ 2024-07-08 37/week @ 2024-07-15 14/week @ 2024-07-22 49/week @ 2024-07-29 25/week @ 2024-08-05 12/week @ 2024-08-12 4/week @ 2024-08-19 18/week @ 2024-08-26 64/week @ 2024-09-02 27/week @ 2024-09-09 11/week @ 2024-09-16 49/week @ 2024-09-23 29/week @ 2024-09-30

117 downloads per month
Used in 4 crates (3 directly)

MIT/Apache

12KB
117 lines

surf-governor

A rate-limiting middleware for surf

Install

With cargo add installed :

cargo add surf-governor

Documentation

Example

use surf_governor::GovernorMiddleware;
use surf::{Client, Request, http::Method};
use url::Url;

#[async_std::main]
async fn main() -> surf::Result<()> {
    let req = Request::new(Method::Get, Url::parse("https://example.api")?);
    let client = Client::new().with(GovernorMiddleware::per_second(1)?);
    let res = client.send(req).await?;
    Ok(())
}

lib.rs:

A surf middleware that implements rate-limiting using governor. The majority of this has been copied from tide-governor

Example

use surf_governor::GovernorMiddleware;
use surf::{Client, Request, http::Method};
use url::Url;

#[async_std::main]
async fn main() -> surf::Result<()> {
    let req = Request::new(Method::Get, Url::parse("https://example.api")?);
    // Construct Surf client with a governor
    let client = Client::new().with(GovernorMiddleware::per_second(30)?);
    let res = client.send(req).await?;
    Ok(())
}

Dependencies

~10–18MB
~252K SLoC