Skip to content
Back to skills

Rate Limiter Middleware

ASecurity

Build API rate-limiting middleware using Token Bucket or Sliding Window algorithms.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
developmentjavascriptgojavanodeexpressfastapiflasktestingapi

Works with

  • api

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 27, 2026

npx -y skills add RMAzrim/opencode-artes --skill rate-limiter-middleware --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rate Limiter Middleware?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rate Limiter Middleware
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/rmazrim-rate-limiter-middleware/badge)](https://www.skillsdirectory.com/skills/rmazrim-rate-limiter-middleware)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: Rate Limiter Middleware
description: Build API rate-limiting middleware using Token Bucket or Sliding Window algorithms.
metadata:
  source: skills/rate-limiter-middleware/rate-limiter-middleware.md
---

# Rate Limiter Middleware

## Prerequisites & Dependencies
- Node.js 18+ with Express (or FastAPI, Flask, Go Gin)
- `npm i express-rate-limit` (Token Bucket) or `npm i rate-limit-redis` (distributed Sliding Window)
- Understanding of API throughput requirements and SLA constraints

## Execution Steps
1. Determine the rate limit: e.g., 100 requests per 15 minutes per IP, or 10 requests per minute per API key
2. Choose the algorithm: 
   - **Token Bucket** (fixed window, allows burst up to bucket size)
   - **Sliding Window** (counts requests in a moving time window, more precise)
3. Install and configure the middleware with `max`, `windowMs`, `standardHeaders: true`, `legacyHeaders: false`
4. Apply the middleware globally or per-route: `app.use('/api', limiter)` or `router.get('/strict', limiter, handler)`
5. Add retry-after header on limit exceed and log exceeded events for SLA monitoring
6. Tune limits based on load testing (e.g., `k6`, `artillery`) and observed traffic patterns

```javascript
// Express Token Bucket rate limiter
const rateLimit = require('express-rate-limit');

const globalLimiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100, // limit each IP to 100 requests per windowMs
  standardHeaders: true, // Return rate limit info in `RateLimit-*` headers
  legacyHeaders: false, // Disable the `X-RateLimit-*` headers
  message: 'Too many requests, please try again later.',
});

app.use('/api', globalLimiter);
app.get('/api/data', (req, res) => res.json({ data: 'hello' }));
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.