#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

#42 in HTTP server

Download history 1005/week @ 2023-12-14 1201/week @ 2023-12-21 1388/week @ 2023-12-28 1193/week @ 2024-01-04 1400/week @ 2024-01-11 895/week @ 2024-01-18 1282/week @ 2024-01-25 1581/week @ 2024-02-01 1295/week @ 2024-02-08 1376/week @ 2024-02-15 1173/week @ 2024-02-22 1406/week @ 2024-02-29 1634/week @ 2024-03-07 1508/week @ 2024-03-14 1314/week @ 2024-03-21 1232/week @ 2024-03-28

5,850 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

~20–35MB
~605K SLoC