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

#427 in HTTP client

Download history 2046/week @ 2025-03-11 1468/week @ 2025-03-18 1066/week @ 2025-03-25 1651/week @ 2025-04-01 1183/week @ 2025-04-08 1342/week @ 2025-04-15 1287/week @ 2025-04-22 1148/week @ 2025-04-29 717/week @ 2025-05-06 667/week @ 2025-05-13 682/week @ 2025-05-20 672/week @ 2025-05-27 787/week @ 2025-06-03 873/week @ 2025-06-10 752/week @ 2025-06-17 620/week @ 2025-06-24

3,122 downloads per month
Used in 4 crates (3 directly)

MIT/Apache

12KB
117 lines

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(())
}

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(())
}

Dependencies

~11–20MB
~251K SLoC