All skills
Skillintermediate

Workers Frameworks

Workers-native web framework with excellent TypeScript support and middleware ecosystem.

Claude Code Knowledge Pack7/10/2026

Overview

Workers Frameworks

Hono (Recommended)

Workers-native web framework with excellent TypeScript support and middleware ecosystem.

npm install hono

Basic Setup


const app = new Hono();

app.get('/', (c) => c.text('Hello World!'));
app.post('/api/users', async (c) => {
  const body = await c.req.json();
  return c.json({ id: 1, ...body }, 201);
});

Typed Environment


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

app.get('/data', async (c) => {
  const value = await c.env.MY_KV.get('key');  // Fully typed
  return c.text(value || 'Not found');
});

Middleware


app.use('*', logger());
app.use('/api/*', cors({ origin: '*' }));

// Custom middleware
app.use('/protected/*', async (c, next) => {
  const auth = c.req.header('Authorization');
  if (!auth?.startsWith('Bearer ')) return c.text('Unauthorized', 401);
  await next();
});

Request Validation (Zod)


const schema = z.object({
  name: z.string().min(1),
  email: z.string().email(),
});

app.post('/users', zValidator('json', schema), async (c) => {
  const validated = c.req.valid('json');  // Type-safe, validated data
  return c.json({ id: 1, ...validated });
});

Error handling: Automatic 400 response with validation errors

Route Groups

const api = new Hono().basePath('/api');

api.get('/users', (c) => c.json([]));
api.post('/users', (c) => c.json({ id: 1 }));

app.route('/', api);  // Mounts at /api/*

Error Handling

app.onError((err, c) => {
  console.error(err);
  return c.json({ error: err.message }, 500);
});

app.notFound((c) => c.json({ error: 'Not Found' }, 404));

Accessing ExecutionContext


  fetch(request: Request, env: Env, ctx: ExecutionContext) {
    return app.fetch(request, env, ctx);
  },
};

// In route handlers:
app.get('/log', (c) => {
  c.executionCtx.waitUntil(logRequest(c.req));
  return c.text('OK');
});

OpenAPI/Swagger (Hono OpenAPI)


const app = new OpenAPIHono();

const route = createRoute({
  method: 'get',
  path: '/users/{id}',
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: { description: 'User found', content: { 'application/json': { schema: z.object({ id: z.string() }) } } },
  },
});

app.openapi(route, (c) => {
  const { id } = c.req.valid('param');
  return c.json({ id });
});

app.doc('/openapi.json', { openapi: '3.0.0', info: { version: '1.0.0', title: 'API' } });

Testing with Hono


describe('API', () => {
  it('GET /', async () => {
    const res = await app.request('/');
    expect(res.status).toBe(200);
    expect(await res.text()).toBe('Hello World!');
  });
});

Other Frameworks

itty-router (Minimalist)


const router = Router();

router.get('/users/:id', ({ params }) => new Response(params.id));

Use case: Tiny bundle size (~500 bytes), simple routing needs

Worktop (Advanced)


const router = new Router();

router.add('GET', '/users/:id', (req, res) => {
  res.send(200, { id: req.params.id });
});

router.listen();

Use case: Advanced routing, built-in CORS/cache utilities

Framework Comparison

FrameworkBundle SizeTypeScriptMiddlewareValidationBest For
Hono~12KBExcellentRichZodProduction apps
itty-router~500BGoodBasicManualMinimal APIs
Worktop~8KBGoodAdvancedManualComplex routing

See Also