A response body formatter middleware for Koa (v0.1.0, stable) that automatically wraps JSON API responses into a consistent envelope with ok, status, errors, and result fields. It supports custom formatter functions, error aggregation, and includes Flowtype definitions. Unmaintained since 2016, no recent releases; suitable for legacy Koa v1/before async/await middleware patterns. Alternatives: koa-respond, koa-json, or manual ctx.body assignment.
npm install koa-formatterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up a basic Koa app with koa-formatter middleware and uses ctx.result to output a formatted JSON response.
Use Koa v1 or wrap async middleware with co.wrap, or migrate to modern alternatives like koa-respond.
Consider rewriting using ctx.body directly or adopt a maintained library (koa-respond, koa-json).
If using TypeScript, create custom type definitions or migrate to TypeScript-native libraries.
Ensure app is an instance of Koa: const app = new Koa(); then app.use(formatter());
Place formatter() early in the middleware chain (before routes) and ensure response logic sets ctx.result instead of ctx.body.