Packages@g14o/ratelimit-hono
Overview
Hono rate limiting with Upstash Redis for middleware and route handlers.
Hono rate limiting with Upstash Redis. Middleware and route handler wrappers over @g14o/ratelimit.
Install
pnpm add @g14o/ratelimit-hono @upstash/redis @upstash/ratelimit hono@upstash/redis and @upstash/ratelimit are optional peers (in-memory fallback without Redis). hono is required.
Quick start
Define your app's Hono Env, then pass it to the factory so handlers get a typed Context:
export interface Bindings {
TOKEN: string;
}
export interface Variables {
user: User;
}
export type AppEnv = { Bindings: Bindings; Variables: Variables };import { createRateLimit } from "@g14o/ratelimit-hono";
import { env } from "./env";
import type { AppEnv } from "../types";
export const { middleware, withRateLimit, checkRateLimit } =
createRateLimit<AppEnv>({
redis: {
url: env.UPSTASH_REDIS_REST_URL,
token: env.UPSTASH_REDIS_REST_TOKEN,
},
});Import helpers from lib/ratelimit.ts in route modules or inline on your app — c.env and c.get(...) are typed automatically. See Setup for full examples.
Framework alternatives
- Web
Request/Response: @g14o/ratelimit - Next.js
NextRequest/NextResponse: @g14o/ratelimit-nextjs - Express
Request/Response: @g14o/ratelimit-express
Import paths
| Use case | Import |
|---|---|
| Rate limit factory | import { createRateLimit } from "@g14o/ratelimit-hono" |
| Custom store helpers | import { createStore, defineStore } from "@g14o/ratelimit-hono" |
| In-memory store | import { memoryStore } from "@g14o/ratelimit-hono/memory" |
| Upstash store | import { upstashStore } from "@g14o/ratelimit-hono/upstash" |
| Redis store (node-redis / ioredis) | import { redisStore } from "@g14o/ratelimit-hono/redis" |
| Redis / env helpers | import { createRedisClient, isBuildLikePhase } from "@g14o/ratelimit/config" |