Expand description
In-memory rate limiting middleware
Fixed window per key (the peer IP by default). State lives in this process, so with several instances each one enforces the limit on its own; put a shared limiter (reverse proxy, Redis) in front for a global limit.
use std::time::Duration;
use ullun::prelude::*;
use ullun::rate_limit::RateLimiter;
App::new()
.middleware(RateLimiter::new(100, Duration::from_secs(60)))
.get("/", |_req: Request| async { Ok(Response::text("ok")) })
.run("127.0.0.1:3000")
.await
.unwrap();Structsยง
- Decision
- Outcome of counting one request
- Rate
Limiter - Fixed-window rate limiter, usable as middleware