https://github.com/aaronerhardt/actix-governor
A middleware for actix-web that provides rate-limiting backed by governor.
https://github.com/aaronerhardt/actix-governor
actix-web governor rate-limiting
Last synced: 2 months ago
JSON representation
A middleware for actix-web that provides rate-limiting backed by governor.
- Host: GitHub
- URL: https://github.com/aaronerhardt/actix-governor
- Owner: AaronErhardt
- License: gpl-3.0
- Created: 2020-12-26T22:56:22.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T10:12:58.000Z (9 months ago)
- Last Synced: 2024-10-14T14:44:40.696Z (8 months ago)
- Topics: actix-web, governor, rate-limiting
- Language: Rust
- Homepage:
- Size: 185 KB
- Stars: 97
- Watchers: 1
- Forks: 19
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://docs.rs/actix-governor/)
[](https://crates.io/crates/actix-governor)# Actix Governor
A middleware for [actix-web](https://github.com/actix/actix-web) that provides
rate-limiting backed by [governor](https://github.com/antifuchs/governor).## Features:
+ Simple to use
+ High customizability
+ High performance
+ Robust yet flexible API## Example
```rust
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`:
```toml
[dependencies]
actix-governor = "0.6"
```