patterntypescriptTip
Hono Framework: Lightweight edge-compatible API framework for TypeScript
Viewed 0 times
honoedgecloudflare-workersweb-standardsfetch-apiruntime-agnostic
Problem
Express and Fastify are not designed for edge runtimes (Cloudflare Workers, Deno Deploy, Bun). They rely on Node.js built-ins that are unavailable or polyfilled inconsistently across edge environments.
Solution
Use Hono for APIs that must run on edge runtimes or need to be runtime-agnostic. Hono uses the standard Fetch API (Request/Response) and runs identically on Node, Bun, Deno, and Cloudflare Workers.
Why
Hono's design around Web Standards means zero polyfilling and predictable behavior across runtimes. Its middleware system is composable and its TypeScript support includes end-to-end type inference for request context.
Gotchas
- Hono's RPC client (hono/client) requires strict TypeScript configuration — ensure strict mode is enabled.
- Hono does not bundle a body size limit by default — add it explicitly for production.
- Hono v3 and v4 have breaking changes in middleware API — pin your version.
Code Snippets
Basic Hono app with typed route and middleware
import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { zValidator } from '@hono/zod-validator'
import { z } from 'zod'
const app = new Hono()
app.use('*', logger())
app.get('/users/:id',
zValidator('param', z.object({ id: z.string() })),
async (c) => {
const { id } = c.req.valid('param')
const user = await db.users.find(id)
if (!user) return c.json({ error: 'NOT_FOUND' }, 404)
return c.json(user)
}
)
export default appRevisions (0)
No revisions yet.