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

actix-governor

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

18 releases

0.7.0 Oct 25, 2024
0.5.0 Oct 4, 2023
0.4.1 Jun 20, 2023
0.4.0 Jan 15, 2023
0.2.3 Dec 31, 2020

#51 in HTTP server

Download history 1894/week @ 2024-07-31 1793/week @ 2024-08-07 2032/week @ 2024-08-14 1817/week @ 2024-08-21 2511/week @ 2024-08-28 2107/week @ 2024-09-04 2151/week @ 2024-09-11 1889/week @ 2024-09-18 1910/week @ 2024-09-25 3592/week @ 2024-10-02 3636/week @ 2024-10-09 3894/week @ 2024-10-16 4705/week @ 2024-10-23 4120/week @ 2024-10-30 4447/week @ 2024-11-06 3120/week @ 2024-11-13

17,174 downloads per month
Used in 7 crates

GPL-3.0-or-later

89KB
1.5K 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
~505K SLoC