#actix #rate-limit #governor

actix-governor

A rate-limiting middleware for actix-web backed by the governor crate

8 releases

Uses new Rust 2021

0.3.0-beta.1 Dec 28, 2021
0.2.6 Dec 28, 2021
0.2.5 Nov 3, 2021
0.2.4 Jan 7, 2021
0.2.3 Dec 31, 2020

#50 in HTTP server

Download history 12/week @ 2021-09-26 24/week @ 2021-10-03 21/week @ 2021-10-10 19/week @ 2021-10-17 10/week @ 2021-10-24 108/week @ 2021-10-31 41/week @ 2021-11-07 40/week @ 2021-11-14 17/week @ 2021-11-21 19/week @ 2021-11-28 9/week @ 2021-12-05 4/week @ 2021-12-12 6/week @ 2021-12-19 90/week @ 2021-12-26 89/week @ 2022-01-02 44/week @ 2022-01-09

229 downloads per month
Used in qsv

GPL-3.0-or-later

29KB
384 lines

CI Docs crates.io

Actix Governor

A middleware for actix-web that provides rate-limiting backed by governor.

Features:

  • Simple to use
  • High performance
  • Robust yet flexible API
  • Actively maintained as part of the Triox-Poject

Example

use actix_governor::{Governor, GovernorConfigBuilder};
use actix_web::{web, App, HttpServer, Responder};

async fn index() -> impl Responder {
    "Hello world!"
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    // Allow bursts with up to five requests per IP address
    // and replenishes one element every two seconds
    let governor_conf = GovernorConfigBuilder::default()
        .per_second(2)
        .burst_size(5)
        .finish()
        .unwrap();

    HttpServer::new(move || {
        App::new()
            // Enable Governor middleware
            .wrap(Governor::new(&governor_conf))
            // Route hello world service
            .route("/", web::get().to(index))
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}

Add this to your Cargo.toml:

[dependencies]
actix-governor = "0.3"

Dependencies

~23MB
~529K SLoC

Oa