1
0
mirror of https://github.com/actix/examples synced 2025-06-27 01:27:43 +02:00

chore: move and document rate limit middleware

This commit is contained in:
Rob Ede
2023-10-29 23:47:02 +00:00
parent cf55f50d1d
commit 5d36d72976
7 changed files with 84 additions and 53 deletions

View File

@ -0,0 +1,21 @@
# Middleware: Rate Limiting
This example showcases two middleware that achieve rate limiting for your API endpoints. One uses a simple leaky-bucket implementation and the other delegates to [`actix-governor`].
## Usage
```sh
cd middleware/rate-limit
cargo run
```
Look in `src/rate_limit.rs` to see the leaky-bucket implementation.
## Routes
- [GET /test/simple](http://localhost:8080/test/simple) - uses the hand-written leaky-bucket rate limiting.
- [GET /test/governor](http://localhost:8080/test/governor) - uses [`actix-governor`].
Calling either of these endpoints too frequently will result in a 429 Too Many Requests response.
[`actix-governor`]: https://crates.io/crates/actix-governor