
@universal-rate-limit/fastify
Fastify plugin for universal-rate-limit — a zero-dependency rate limiter built on web standards. Supports fixed-window and sliding-window algorithms, pluggable stores (memory, Redis, or your own), and IETF-compliant rate limit headers out of the box.
Install
bash
npm install @universal-rate-limit/fastifyUsage
ts
import Fastify from 'fastify';
import { fastifyRateLimit } from '@universal-rate-limit/fastify';
const fastify = Fastify();
await fastify.register(fastifyRateLimit, {
windowMs: 60_000, // 1 minute
limit: 60 // 60 requests per window
});
fastify.get('/', async () => {
return { hello: 'world' };
});
await fastify.listen({ port: 3000 });Options
Accepts all core options — windowMs, limit, algorithm, store, keyGenerator, skip, handler, message, statusCode, headers, and passOnStoreError.
Example
See examples/fastify for a complete working app with integration tests.
Documentation
License
MIT