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

#497 in HTTP client

Download history 44/week @ 2024-01-01 2/week @ 2024-01-08 5/week @ 2024-01-29 212/week @ 2024-02-05 18/week @ 2024-02-12 13/week @ 2024-02-19 109/week @ 2024-02-26 23/week @ 2024-03-04 23/week @ 2024-03-11 15/week @ 2024-03-18 132/week @ 2024-03-25 38/week @ 2024-04-01 11/week @ 2024-04-08 34/week @ 2024-04-15

216 downloads per month
Used in 3 crates (2 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–19MB
~260K SLoC