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

#222 in HTTP client

Download history 107/week @ 2023-07-31 77/week @ 2023-08-07 101/week @ 2023-08-14 86/week @ 2023-08-21 97/week @ 2023-08-28 88/week @ 2023-09-04 51/week @ 2023-09-11 79/week @ 2023-09-18 102/week @ 2023-09-25 135/week @ 2023-10-02 86/week @ 2023-10-09 111/week @ 2023-10-16 126/week @ 2023-10-23 125/week @ 2023-10-30 61/week @ 2023-11-06 47/week @ 2023-11-13

377 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

~8–16MB
~230K SLoC