Skip to content

@universal-rate-limit/fastify

@universal-rate-limit/fastify

npm versionnpm downloadstypeslicense

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/fastify

Usage

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 optionswindowMs, limit, algorithm, store, keyGenerator, skip, handler, message, statusCode, headers, and passOnStoreError.

Example

See examples/fastify for a complete working app with integration tests.

Documentation

View the full documentation

License

MIT

Released under the MIT License.