Skip to main content

api-rate-limit-hono

@rtorcato/api-rate-limit-hono is the Hono adapter for api-rate-limit. It applies a sliding-window limit per client and responds 429 when the limit is exceeded.

Install

pnpm add @rtorcato/api-rate-limit @rtorcato/api-rate-limit-hono hono

hono is a peer dependency (^4) — you bring your own version.

Usage

import { rateLimitMiddleware } from '@rtorcato/api-rate-limit-hono'

app.use(rateLimitMiddleware({
requests: 100, // max requests per key
windowMs: 60_000, // sliding window: 1 minute
}))

Keys on X-Forwarded-ForX-Real-IP'unknown'. When the limit is exceeded it responds 429 with the standard error envelope { error: 'TooManyRequestsError', code: 'too_many_requests', message } from api-errors.

Per-route limits

app.use('/auth/*', rateLimitMiddleware({ requests: 10, windowMs: 60_000 }))