hono-rate-limiter is a middleware library designed for the Hono web framework, providing robust rate-limiting capabilities for both HTTP API endpoints and WebSocket connections. Its current stable version is 0.5.3, with minor releases occurring relatively frequently, indicating active development. The library is inspired by the widely-used `express-rate-limit` and aims to bring similar comprehensive functionality to Hono applications, focusing on developer experience and flexibility. A key differentiator is its flexible storage mechanism, now supporting Unstorage, which allows developers to integrate various backends like Redis, Cloudflare KV, or file systems for persistent rate limit tracking. It simplifies the process of protecting Hono routes from abuse and ensures API stability under high traffic, offering fine-grained control over rate limits and responses.
npm install hono-rate-limiterVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and apply the `rateLimiter` middleware to a Hono application, configure basic limits, and use an in-memory store.
Migrate to using `@hono-rate-limiter/cloudflare` for Cloudflare-specific stores. Review documentation for updated configuration.
Ensure `keyGenerator` is explicitly provided in your `rateLimiter` configuration, e.g., `keyGenerator: (c) => c.req.ip`.
Install and configure a dedicated Redis store package (e.g., `@hono-rate-limiter/redis`) or an `unstorage` Redis driver, and pass an instance to the `store` option.
Keep an eye on the changelog for new releases, report issues, and be prepared for potential minor breaking changes. Pinning to specific minor versions might be advisable in production.
Add `keyGenerator: (c) => c.req.ip` or a custom function to your `rateLimiter` options.
Ensure you are passing a valid store instance, e.g., `store: new MemoryStore()` or `store: new RedisStore(...)` after installing the appropriate package.
Use ESM named imports: `import { rateLimiter } from 'hono-rate-limiter';`.