[][src]Crate tide_governor

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

Structs

GovernorMiddleware

Once the rate limit has been reached, the middleware will respond with status code 429 (too many requests) and a Retry-After header with the amount of time that needs to pass before another request will be allowed.