hono-api-scaffolder
jezweb/claude-skills
Scaffold Hono API routes, middleware, and documentation for Cloudflare Workers.
What is hono-api-scaffolder?
Generates structured API route files, Zod validation schemas, middleware, and endpoint documentation for Hono-based Cloudflare Workers projects. Use this after setting up a project with cloudflare-worker-builder or vite-flare-starter to quickly add typed, validated API endpoints.
- Creates route files organized by resource (users, posts, auth, etc.) with CRUD operations
- Generates Zod validation schemas for request bodies with automatic type inference
- Produces middleware templates for authentication, CORS, and error handling
- Wires routes into the main entry point with proper error handling
- Generates API_ENDPOINTS.md documentation for all endpoints
- Provides end-to-end type safety between Worker and client via Hono RPC
How to install hono-api-scaffolder
npx skills add https://github.com/jezweb/claude-skills --skill hono-api-scaffolder- Existing Cloudflare Workers project initialized with cloudflare-worker-builder or vite-flare-starter
- Node.js and pnpm installed
- @hono/zod-validator and zod packages (installed via pnpm add)
How to use hono-api-scaffolder
- 1.Determine the API endpoints needed, grouped by resource (users, posts, auth, etc.)
- 2.Use the route-template.ts to create one file per resource group in src/routes/
- 3.Add Zod validation schemas for POST/PUT request bodies using @hono/zod-validator
- 4.Create middleware files (auth, CORS, error handling) using the middleware-template.ts
- 5.Mount all route files in src/index.ts using app.route()
- 6.Define typed Env interface in src/types.ts with DB, KV, R2, and secret bindings
- 7.Generate API_ENDPOINTS.md using the endpoint-docs-template.md format
Use cases
- Adding REST API endpoints to an existing Cloudflare Workers project
- Creating validated CRUD operations for database resources
- Setting up authentication middleware and protected routes
- Generating API documentation automatically from route definitions
- Ensuring type safety between backend Worker and frontend client
- Backend developers building APIs on Cloudflare Workers
- Full-stack developers using Hono with D1, KV, or R2 bindings
- Teams needing rapid API scaffolding with built-in validation
- Developers wanting end-to-end TypeScript type safety
hono-api-scaffolder FAQ
Use it after your Cloudflare Workers project shell exists (via cloudflare-worker-builder or vite-flare-starter) and you need to add API routes, create endpoints, or generate API documentation.
For fewer than 10 endpoints, use a single index.ts. For 10–30 endpoints, create route files per resource in src/routes/. For 30+ endpoints, add shared middleware and typed context.
Export the app type from your Worker (export type AppType = typeof app), then use the Hono Client (hc) on the client side to get fully typed API calls.
Zod with @hono/zod-validator, which validates request bodies and automatically infers TypeScript types.
fetch() follows redirects silently, so if an error returns HTML, the client will try to parse it as JSON and fail. Always return JSON error responses.
Full instructions (SKILL.md)
Source of truth, from jezweb/claude-skills.
name: hono-api-scaffolder description: "Scaffold Hono API routes for Cloudflare Workers. Produces route files, middleware, typed bindings, Zod validation, error handling, and API_ENDPOINTS.md documentation. Use after a project is set up with cloudflare-worker-builder or vite-flare-starter, when you need to add API routes, create endpoints, or generate API documentation." compatibility: claude-code-only
Hono API Scaffolder
Add structured API routes to an existing Cloudflare Workers project. This skill runs AFTER the project shell exists (via cloudflare-worker-builder or vite-flare-starter) and produces route files, middleware, and endpoint documentation.
Workflow
Step 1: Gather Endpoints
Determine what the API needs. Either ask the user or infer from the project description. Group endpoints by resource:
Users: GET /api/users, GET /api/users/:id, POST /api/users, PUT /api/users/:id, DELETE /api/users/:id
Posts: GET /api/posts, GET /api/posts/:id, POST /api/posts, PUT /api/posts/:id
Auth: POST /api/auth/login, POST /api/auth/logout, GET /api/auth/me
Step 2: Create Route Files
One file per resource group. Use the template from assets/route-template.ts:
// src/routes/users.ts
import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator'
import { z } from 'zod'
import type { Env } from '../types'
const app = new Hono<{ Bindings: Env }>()
// GET /api/users
app.get('/', async (c) => {
const db = c.env.DB
const { results } = await db.prepare('SELECT * FROM users').all()
return c.json({ users: results })
})
// GET /api/users/:id
app.get('/:id', async (c) => {
const id = c.req.param('id')
const user = await db.prepare('SELECT * FROM users WHERE id = ?').bind(id).first()
if (!user) return c.json({ error: 'Not found' }, 404)
return c.json({ user })
})
// POST /api/users
const createUserSchema = z.object({
name: z.string().min(1),
email: z.string().email(),
})
app.post('/', zValidator('json', createUserSchema), async (c) => {
const body = c.req.valid('json')
// ... insert logic
return c.json({ user }, 201)
})
export default app
Step 3: Add Middleware
Based on project needs, add from assets/middleware-template.ts:
Auth middleware — protect routes requiring authentication:
import { createMiddleware } from 'hono/factory'
import type { Env } from '../types'
export const requireAuth = createMiddleware<{ Bindings: Env }>(async (c, next) => {
const token = c.req.header('Authorization')?.replace('Bearer ', '')
if (!token) return c.json({ error: 'Unauthorized' }, 401)
// Validate token...
await next()
})
CORS — use Hono's built-in:
import { cors } from 'hono/cors'
app.use('/api/*', cors({ origin: ['https://example.com'] }))
Step 4: Wire Routes
Mount all route groups in the main entry point:
// src/index.ts
import { Hono } from 'hono'
import type { Env } from './types'
import users from './routes/users'
import posts from './routes/posts'
import auth from './routes/auth'
import { errorHandler } from './middleware/error-handler'
const app = new Hono<{ Bindings: Env }>()
// Global error handler
app.onError(errorHandler)
// Mount routes
app.route('/api/users', users)
app.route('/api/posts', posts)
app.route('/api/auth', auth)
// Health check
app.get('/api/health', (c) => c.json({ status: 'ok' }))
export default app
Step 5: Create Types
// src/types.ts
export interface Env {
DB: D1Database
KV: KVNamespace // if needed
R2: R2Bucket // if needed
API_SECRET: string // secrets
}
Step 6: Generate API_ENDPOINTS.md
Document all endpoints. See references/endpoint-docs-template.md for the format:
## POST /api/users
Create a new user.
- **Auth**: Required (Bearer token)
- **Body**: `{ name: string, email: string }`
- **Response 201**: `{ user: User }`
- **Response 400**: `{ error: string, details: ZodError }`
Key Patterns
Zod Validation
Always validate request bodies with @hono/zod-validator:
import { zValidator } from '@hono/zod-validator'
app.post('/', zValidator('json', schema), async (c) => {
const body = c.req.valid('json') // fully typed
})
Install: pnpm add @hono/zod-validator zod
Error Handling
Use the standard error handler from assets/error-handler.ts:
export const errorHandler = (err: Error, c: Context) => {
console.error(err)
return c.json({ error: err.message }, 500)
}
API routes must return JSON errors, not redirects. fetch() follows redirects silently, then the client tries to parse HTML as JSON.
RPC Type Safety
For end-to-end type safety between Worker and client:
// Worker: export the app type
export type AppType = typeof app
// Client: use hc (Hono Client)
import { hc } from 'hono/client'
import type { AppType } from '../worker/src/index'
const client = hc<AppType>('https://api.example.com')
const res = await client.api.users.$get() // fully typed
Route Groups vs Single File
| Project size | Structure |
|---|---|
| < 10 endpoints | Single index.ts with all routes |
| 10-30 endpoints | Route files per resource (routes/users.ts) |
| 30+ endpoints | Route files + shared middleware + typed context |
Reference Files
| When | Read |
|---|---|
| Hono patterns, middleware, RPC | references/hono-patterns.md |
| API_ENDPOINTS.md format | references/endpoint-docs-template.md |
Assets
| File | Purpose |
|---|---|
| assets/route-template.ts | Starter route file with CRUD + Zod |
| assets/middleware-template.ts | Auth middleware template |
| assets/error-handler.ts | Standard JSON error handler |
Related skills
More from jezweb/claude-skills and the wider catalog.

hono-routing
|

icon-set-generator
Generate cohesive, project-specific SVG icon sets with consistent style and visual weight.

image-processing
Resize, crop, convert, and optimize images for web—PNG/WebP/JPG, thumbnails, OG cards, powered by Pillow.

landing-page
Generate a complete, deployable landing page from a brief as a single HTML file.

mcp-builder
Build and deploy MCP servers in Python with FastMCP—expose tools, resources, and prompts to Claude.

motion
|