hono

Hono

Hono web framework for edge runtimes: typed routes, middleware, RPC client

Deno
framework
Used by 116 projects

Details

Language / Topic
denoDeno
Category
framework
Compatible Frameworks
hono

Rules

balanced
- In Deno projects: Define routes using Hono app methods like `app.get(path, handler)`, specifying HTTP method and path.
- Use context `c` for requests (`c.req.json()`, `c.req.query()`) and responses (`c.json(data, status)`).
- Implement try-catch in handlers to return standardized errors: `c.json({ cause: error.cause || error.message }, 400)`.
- Prefer functional handlers with early returns for readability.
- In Deno projects: Define typed routes with Zod validator middleware: `app.post('/users', zValidator('json', createUserSchema), async (c) => { const body = c.req.valid('json'); ... return c.json(user, 201) })` — `c.req.valid('json')` returns the parsed, typed body.
- Read request data via context: `c.req.json<T>()` for body, `c.req.query('page')` for query params, `c.req.param('id')` for path params — always `await` `.json()`.
- Return responses with explicit status: `c.json({ error: 'not found' }, 404)`, `c.text('ok', 200)`, `c.body(stream, 200)` — never send a response without a status code.
- Use `app.use('*', cors())` and `app.use('*', logger())` for cross-cutting middleware — Hono middleware runs in registration order.
- Export the `AppType` for use with the Hono RPC client: `export type AppType = typeof app; const client = hc<AppType>('http://localhost:3000')` — fully typed API calls with no code generation.