Expand description
General-purpose middlewares for the router.
Currently provides rate_limiter, a per-caller request-cap hook. Attach the
returned Middleware to a route or pass it as a
global middleware so over-limit requests fail with a 429 before the handler runs.
ⓘ
let mw = rate_limiter(limiter, 100);
self.mount_get(&mut router, "/list", desc, handler, vec![mw]);Functions§
- rate_
limiter - Builds middleware enforcing
limitrequests per minute per caller. The caller key is the context’s user id, or thex-forwarded-forheader value falling back to"anonymous". Over-limit requests fail with a 429ErrorResult.