koa-body is a robust middleware for the Koa.js web framework designed to parse various request body types. It supports `multipart/form-data` for file uploads, `application/x-www-form-urlencoded`, and `application/json` payloads. Functionally, it offers similar capabilities to a combination of Express's `bodyParser` and `multer`. The current stable version is 7.0.1, and the project is actively maintained by the Koa community, demonstrating a healthy release cadence with recent updates in 2025. Key differentiators include its seamless integration with Koa's middleware system, comprehensive content-type support, and flexible options for patching the parsed body to Koa's context (`ctx.request.body`) or Node's native request object (`ctx.req.body`), alongside configurable limits for body and file sizes.
npm install koa-bodyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a Koa application with `koa-body` to parse JSON, urlencoded, and multipart request bodies. It logs the parsed body and any uploaded files, then responds with a confirmation message.
Review the official v7.0.0 changelog on GitHub for detailed internal changes, especially if you relied on specific internal properties or unparsed body access methods. Update your TypeScript types if encountering issues.
If you need to parse bodies for other HTTP methods, configure the `parsedMethods` option: `app.use(koaBody({ parsedMethods: ['POST', 'PUT', 'PATCH', 'GET', 'DELETE'] }));`. Be aware of HTTP specification implications when sending bodies with `GET` or `DELETE` requests.Access `ctx.request.body` for unsupported text types. For other scenarios requiring the raw body (e.g., cryptographic verification), set `includeUnparsed: true` in options and access `ctx.request.rawBody`.
Enable multipart parsing by setting `multipart: true` in the `koaBody` options: `app.use(koaBody({ multipart: true }));`.Ensure `app.use(koaBody());` is called before routes that expect a body. If expecting bodies on other HTTP methods, configure `parsedMethods` option: `koaBody({ parsedMethods: ['POST', 'GET'] })`.Increase the relevant size limit in the `koaBody` options, e.g., `koaBody({ jsonLimit: '5mb', formLimit: '2mb' });`. Defaults are `1mb` for JSON and `56kb` for form/text.Set `multipart: true` in the `koaBody` options: `koaBody({ multipart: true });`. Also, ensure your HTML form has `enctype="multipart/form-data"` or your API client sends the correct `Content-Type` header.