Skip to content

docs: rate limiting recipe + reference middleware #627

Description

@SisyphusZheng

Summary

Provide an official rate limiting recipe with documentation and a reference middleware implementation. No mainstream framework bundles rate limiting internally — all provide it as a recipe or middleware pattern.

Competitive context

Framework Rate Limiting
Next.js Recipe (Upstash/Redis in middleware.ts)
SvelteKit User implements in hooks.server.js
Astro User implements in onRequest middleware
Fresh User implements in _middleware.ts
openElement Zero documentation or templates

Proposed deliverable

  1. Recipe doc (docs/integrations/rate-limiting.md):

    • In-memory sliding window (dev/single-instance)
    • Upstash Redis (production/multi-instance)
    • Deno KV (Deno Deploy)
  2. Reference middleware (not a package — a documented pattern):

// app/middleware/rate-limit.ts
export function rateLimit(opts: { window: number; max: number }) {
  const store = new Map<string, { count: number; reset: number }>();
  return async (c, next) => {
    const key = c.req.header('x-forwarded-for') || 'unknown';
    // ... sliding window check
    if (exceeded) return c.text('Too Many Requests', 429);
    await next();
  };
}
  1. Integration point: document how to attach via _middleware.ts (existing Hono middleware seam)

Non-goals

  • No @openelement/rate-limit package
  • No built-in Redis/KV dependency
  • No per-route configuration API (use Hono middleware composition)

Target version

0.43.0 (documentation + recipe)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions