throttle-ro

Crates.iothrottle-ro
lib.rsthrottle-ro
version0.1.2
created_at2025-05-24 04:13:55.064166+00
updated_at2025-08-14 05:43:58.705439+00
descriptionA configurable throttling service for rate limiting IP-based requests
homepage
repositoryhttps://github.com/kak-smko/throttle-ro
max_upload_size
id1686998
size32,387
Kak Smko (kak-smko)

documentation

https://docs.rs/throttle-ro

README

Throttles Service

Crates.io Documentation License

A configurable rate limiting service for Rust applications, providing IP-based request throttling with cache-backed storage.

Features

  • 🚦 IP-based request throttling
  • ⏱️ Configurable time windows
  • 🔢 Multiple limit tiers
  • 💾 Cache-backed storage (memory or persistent)
  • ⚡ Optional async support

Installation

Add to your Cargo.toml:

[dependencies]
throttle-ro = "0.1"

Usage

Basic Example

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!");
    }
}

API Reference

Full documentation is available on docs.rs.

Contributing

Contributions are welcome! Please open an issue or submit a PR for:

  • New features

  • Performance improvements

  • Bug fixes

License

Dual-licensed under MIT or Apache 2.0 at your option.

Commit count: 1

cargo fmt