hono-patternslisted
Install: claude install-skill smicolon/ai-kit
# Hono Patterns
Core patterns for building Hono applications.
## Routing Patterns
### Modular Route Organization
Organize routes in separate files and compose with `app.route()`:
```typescript
// routes/users.ts
import { Hono } from 'hono'
import type { Env } from '../types/bindings'
const users = new Hono<Env>()
users.get('/', (c) => c.json({ users: [] }))
users.get('/:id', (c) => c.json({ id: c.req.param('id') }))
users.post('/', (c) => c.json({ created: true }, 201))
export { users }
// index.ts
import { users } from './routes/users'
import { posts } from './routes/posts'
app.route('/api/users', users)
app.route('/api/posts', posts)
```
### Route Groups with Shared Middleware
```typescript
const api = new Hono<Env>()
// Apply auth to all /api routes
api.use('*', authMiddleware)
api.route('/users', users)
api.route('/posts', posts)
app.route('/api', api)
// Public routes remain unprotected
app.get('/health', (c) => c.json({ status: 'ok' }))
```
### Chained Route Definition (for RPC)
```typescript
// Chain routes for proper type inference
const routes = app
.get('/users', (c) => c.json({ users: [] }))
.post('/users', (c) => c.json({ created: true }, 201))
.get('/users/:id', (c) => c.json({ id: c.req.param('id') }))
export type AppType = typeof routes
```
## Handler Patterns
### Basic Handler
```typescript
app.get('/users', async (c) => {
const users = await fetchUsers()
return c.json(users)
})
```
### Handler with Validation
```typescript
im