| Crates.io | throttle-ro |
| lib.rs | throttle-ro |
| version | 0.1.2 |
| created_at | 2025-05-24 04:13:55.064166+00 |
| updated_at | 2025-08-14 05:43:58.705439+00 |
| description | A configurable throttling service for rate limiting IP-based requests |
| homepage | |
| repository | https://github.com/kak-smko/throttle-ro |
| max_upload_size | |
| id | 1686998 |
| size | 32,387 |
A configurable rate limiting service for Rust applications, providing IP-based request throttling with cache-backed storage.
Add to your Cargo.toml:
[dependencies]
throttle-ro = "0.1"
use std::time::Duration;
use throttle_ro::ThrottlesService;
use cache_ro::Cache;
fn main() {
let cache = Cache::new(Default::default()); // Configure properly in production
let ip = "127.0.0.1".to_string();
// Allow 5 requests per minute per IP
let mut throttle = ThrottlesService::new(
ip,
5,
Duration::from_secs(60),
"api_"
);
if throttle.can_go(&cache) {
throttle.hit(&cache);
// Process request...
} else {
// Reject request
println!("Rate limit exceeded!");
}
}
Full documentation is available on docs.rs.
Contributions are welcome! Please open an issue or submit a PR for:
New features
Performance improvements
Bug fixes
Dual-licensed under MIT or Apache 2.0 at your option.