Migrating from Express
Shokupan is designed to feel familiar to Express developers. This guide shows you how to migrate your Express app.
Key Differences
Section titled “Key Differences”- Context vs Req/Res: Single
ctxobject instead of separatereqandres - Return vs Send: Return values directly instead of calling
res.json() - Built-in Parsing: Body parsing is automatic
- Async by Default: All handlers are naturally async
- Web Standards: Uses
Headers,URL,Responsefrom web standards
Basic Server
Section titled “Basic Server”Express:
import express from 'express';const app = express();app.get('/', (req, res) => { res.json({ message: 'Hello' });});app.listen(3000);Shokupan:
import { Shokupan } from 'shokupan';const app = new Shokupan({ port: 3000 });app.get('/', (ctx) => { return { message: 'Hello' };});app.listen();Middleware
Section titled “Middleware”Express:
app.use((req, res, next) => { console.log(req.method, req.path); next();});Shokupan:
app.use(async (ctx, next) => { console.log(ctx.method, ctx.path); return next(); // Must return!});Migration Checklist
Section titled “Migration Checklist”- Replace
reqandreswithctx - Change
res.json()toreturn - Remove
express.json()middleware - Return values from middleware
- Update header access:
req.headers.key→ctx.headers.get('key') - Update query params:
req.query.key→ctx.query.get('key')
Next Steps
Section titled “Next Steps”- Routing - Learn Shokupan patterns
- Controllers - Use decorators