Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/KernelErr/poem-ratelimit
Rate limit middleware for poem web framework.
https://github.com/KernelErr/poem-ratelimit
Last synced: 1 day ago
JSON representation
Rate limit middleware for poem web framework.
- Host: GitHub
- URL: https://github.com/KernelErr/poem-ratelimit
- Owner: KernelErr
- License: apache-2.0
- Created: 2022-03-09T11:08:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-05T14:08:37.000Z (5 months ago)
- Last Synced: 2024-11-10T01:03:24.625Z (2 days ago)
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-zh - poem-ratelimit - poem限流中间件
README
# Rate limit middleware for Poem framework
## Usage
Check [examples](./examples), `poem-ratelimit` is available on [crates.io](https://crates.io/crates/poem-ratelimit).
A `yaml` configuration file is used to set limit for global service, per IP and route:
```yaml
global:
# Global limit for all connections
max_requests: 20
# Seconds to refresh limit, we allow 20req/30s here
time_window: 30
ip:
# QPS limit for a single client IP
max_requests: 10
time_window: 30
route:
/:
# QPS limit for a single route
max_requests: 5
time_window: 30
```## How it works
For every requests, we use sliding window algorithm to check if the request is processable. Sorted lists with key like IP, route is stored in Redis. You can check the `lua` script in `lib.rs`.
## License
`poem-ratelimit` is licensed under Apache-2.0.