#rate-limiting #governor #actix

actix-governor

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

16 releases

0.5.0 Oct 4, 2023
0.4.1 Jun 20, 2023
0.4.0 Jan 15, 2023
0.4.0-beta.3 Dec 5, 2022
0.2.3 Dec 31, 2020

#100 in HTTP server

Download history 1508/week @ 2024-03-14 1306/week @ 2024-03-21 1459/week @ 2024-03-28 1648/week @ 2024-04-04 1596/week @ 2024-04-11 1508/week @ 2024-04-18 1492/week @ 2024-04-25 1556/week @ 2024-05-02 1755/week @ 2024-05-09 2180/week @ 2024-05-16 2081/week @ 2024-05-23 2718/week @ 2024-05-30 2044/week @ 2024-06-06 2370/week @ 2024-06-13 2045/week @ 2024-06-20 1714/week @ 2024-06-27

8,523 downloads per month
Used in 6 crates

GPL-3.0-or-later

82KB
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 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.4"

Dependencies

~17–31MB
~528K SLoC