You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A single-purpose koa middleware to only parse JSON request bodies and nothing else.
By default, this libarary parses all valid JSON bodies on POST, PUT, and PATCH requests, and assigns the value to ctx.request.body.
If there is a JSON parsing error, or if the request is not of valid type, ctx.request.body is not set, and will be undefined. If the JSON request payload is too large (by default, the limit is 1mb), a 413 Payload Too Large error will be thrown.
To ensure ctx.request.body contains an empty object {} (rather than undefined) on missing/invalid payloads, you can set the fallback option to true.
Installation
yarn add koa-json-body
or via npm:
npm install koa-json-body --save
Options
fallback - when set to true, ctx.request.body will always contain {} upon missing or invalid payloads. (default: false)
limit - number or string representing the request size limit (default: 1mb)
strict - when set to true, koa-json-body will only accept arrays and objects. (default: true)