Skip to content

Migrating from Koa

Shokupan’s context-based approach is heavily inspired by Koa, making it a very natural transition.

  1. Return Value: Shokupan handlers return data directly instead of setting ctx.body.
  2. Routing: Shokupan has a built-in router; Koa requires koa-router or similar.
  3. Body Parsing: Built-in; no need for koa-bodyparser.

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');
});
FeatureKoaShokupan
Request Bodyctx.request.body (with middleware)ctx.body (built-in)
Query Stringctx.queryctx.query (URLSearchParams)
Sending Textctx.body = 'Hello'return 'Hello' or return ctx.text('Hello')
Sending JSONctx.body = { foo: 'bar' }return { foo: 'bar' }
Status Codectx.status = 404return ctx.text('Not Found', 404)