#rate-limiting #web-server #governor #actix

actix-governor

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

19 unstable releases (6 breaking)

new 0.8.0 Dec 12, 2024
0.7.0 Oct 25, 2024
0.6.0 Sep 16, 2024
0.5.0 Oct 4, 2023
0.2.3 Dec 31, 2020

#61 in HTTP server

Download history 2060/week @ 2024-08-24 2361/week @ 2024-08-31 2002/week @ 2024-09-07 1977/week @ 2024-09-14 1938/week @ 2024-09-21 2593/week @ 2024-09-28 3849/week @ 2024-10-05 3958/week @ 2024-10-12 4438/week @ 2024-10-19 4120/week @ 2024-10-26 4561/week @ 2024-11-02 3472/week @ 2024-11-09 3339/week @ 2024-11-16 3778/week @ 2024-11-23 4000/week @ 2024-11-30 4167/week @ 2024-12-07

15,784 downloads per month
Used in 7 crates

GPL-3.0-or-later

92KB
2K SLoC

CI Docs crates.io

Actix Governor

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

Features:

  • Simple to use
  • High customizability
  • High performance
  • Robust yet flexible API

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 two elements per second
    let governor_conf = GovernorConfigBuilder::default()
        .requests_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.6"

Dependencies

~18–30MB
~511K SLoC