| Crates.io | actix-governor |
| lib.rs | actix-governor |
| version | 0.10.0 |
| created_at | 2020-12-27 20:28:58.41739+00 |
| updated_at | 2025-10-12 20:26:45.392484+00 |
| description | A rate-limiting middleware for actix-web backed by the governor crate |
| homepage | |
| repository | https://github.com/AaronErhardt/actix-governor |
| max_upload_size | |
| id | 327979 |
| size | 181,564 |
A middleware for actix-web that provides rate-limiting backed by governor.
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
}
Cargo.toml:[dependencies]
actix-governor = "0.6"