4 stable releases

1.0.3 Sep 16, 2021
1.0.2 Dec 25, 2020
1.0.0 Dec 24, 2020

#5 in #governor

Download history 12/week @ 2024-07-29 9/week @ 2024-09-23 5/week @ 2024-09-30

2,372 downloads per month

MIT license

8KB
107 lines

tide-governor

A tide middleware that provides rate-limiting functionality backed by governor

Example

use tide_governor::GovernorMiddleware;
use std::env;

#[async_std::main]
async fn main() -> tide::Result<()> {
    let mut app = tide::new();
    app.at("/")
        .with(GovernorMiddleware::per_minute(4)?)
        .get(|_| async move { todo!() });
    app.at("/foo/:bar")
        .with(GovernorMiddleware::per_hour(360)?)
        .put(|_| async move { todo!() });

    app.listen(format!("http://localhost:{}", env::var("PORT")?))
        .await?;
    Ok(())
}

lib.rs:

A tide middleware that implements rate-limiting using governor.

Example

use tide_governor::GovernorMiddleware;
use std::env;

#[async_std::main]
async fn main() -> tide::Result<()> {
    let mut app = tide::new();
    app.at("/")
        .with(GovernorMiddleware::per_minute(4)?)
        .get(|_| async move { todo!() });
    app.at("/foo/:bar")
        .with(GovernorMiddleware::per_hour(360)?)
        .put(|_| async move { todo!() });

    app.listen(format!("http://localhost:{}", env::var("PORT")?))
        .await?;
    Ok(())
}

Dependencies

~12–23MB
~325K SLoC