Migrating from Koa
Shokupan’s context-based approach is heavily inspired by Koa, making it a very natural transition.
Key Differences
Section titled “Key Differences”- Return Value: Shokupan handlers return data directly instead of setting
ctx.body. - Routing: Shokupan has a built-in router; Koa requires
koa-routeror similar. - Body Parsing: Built-in; no need for
koa-bodyparser.
Middleware
Section titled “Middleware”Both frameworks use similar middleware patterns with await next().
Koa:
app.use(async (ctx, next) => { await next(); ctx.set('X-Response-Time', '10ms');});Shokupan:
app.use(async (ctx, next) => { // Wait for downstream await next();
// Modify headers after handler completes ctx.response.headers.set('X-Response-Time', '10ms');});Context Comparison
Section titled “Context Comparison”| Feature | Koa | Shokupan |
|---|---|---|
| Request Body | ctx.request.body (with middleware) | ctx.body (built-in) |
| Query String | ctx.query | ctx.query (URLSearchParams) |
| Sending Text | ctx.body = 'Hello' | return 'Hello' or return ctx.text('Hello') |
| Sending JSON | ctx.body = { foo: 'bar' } | return { foo: 'bar' } |
| Status Code | ctx.status = 404 | return ctx.text('Not Found', 404) |
Migration Checklist
Section titled “Migration Checklist”Next Steps
Section titled “Next Steps”- Core Concepts - Learn Shokupan patterns
- Controllers - Use Class-based routing