![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
koa-json-body
Advanced tools
Readme
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
.
yarn add koa-json-body
or via npm:
npm install koa-json-body --save
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
)Additional options available via co-body.
On a every route:
const body = require('koa-json-body')
app.use(body({ limit: '10kb', fallback: true }))
app.use((ctx, next) => {
console.log(ctx.request.body)
})
On a per-route basis (this example uses koa-router):
const body = require('koa-json-body')({ limit: '10kb' })
app.post('/users', body, (ctx, next) => {
console.log(ctx.request.body)
})
To test, simply run
yarn test
For koa 0.x and 1.x support, see the koa-1 branch.
FAQs
Single-purpose koa middleware to parse valid JSON request bodies and nothing else.
The npm package koa-json-body receives a total of 1,680 weekly downloads. As such, koa-json-body popularity was classified as popular.
We found that koa-json-body demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.