cloudflare-demos

rate-limit Rate Limiting

Per-key limits on the edge โ€” source on GitHub

src/index.ts
import { Hono } from 'hono'

const app = new Hono<{ Bindings: Env }>()

app.get('/', async (c) => {
  const key = c.req.header('cf-connecting-ip') ?? 'anonymous'
  const { success } = await c.env.RATE_LIMITER.limit({ key })
  if (!success) {
    return c.text('Too Many Requests', 429)
  }
  return c.text('OK')
})

export default app
Try it โ€” requests go to a Dynamic Worker running this code. State is isolated per browser session and expires after a while.
response will appear here
response