Gathering detailed insights and metrics for koa-bodyparser
Gathering detailed insights and metrics for koa-bodyparser
Gathering detailed insights and metrics for koa-bodyparser
Gathering detailed insights and metrics for koa-bodyparser
npm install koa-bodyparser
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,313 Stars
110 Commits
118 Forks
19 Watching
5 Branches
33 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-13.6%
111,063
Compared to previous day
Last week
-6%
628,558
Compared to previous week
Last month
5.7%
2,761,980
Compared to previous month
Last year
-2.4%
29,393,958
Compared to previous year
Koa body parsing middleware, based on co-body. support json
, form
and text
type body.
Parse incoming request bodies in a middleware before your handlers, available under the ctx.request.body
property.
âš Notice: This module doesn't support parsing multipart format data, please use
@koa/multer
to parse multipart format data.
1$ npm i @koa/bodyparser --save
1const Koa = require("koa"); 2const { bodyParser } = require("@koa/bodyparser"); 3 4const app = new Koa(); 5app.use(bodyParser()); 6 7app.use((ctx) => { 8 // the parsed body will store in ctx.request.body 9 // if nothing was parsed, body will be an empty object {} 10 ctx.body = ctx.request.body; 11});
patchNode: patch request body to Node's ctx.req
, default is false
.
enableTypes: parser will only parse when request type hits enableTypes, support json/form/text/xml
, default is ['json', 'form']
.
encoding: requested encoding. Default is utf-8
by co-body
.
formLimit: limit of the urlencoded
body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 56kb
.
jsonLimit: limit of the json
body. Default is 1mb
.
textLimit: limit of the text
body. Default is 1mb
.
xmlLimit: limit of the xml
body. Default is 1mb
.
jsonStrict: when set to true, JSON parser will only accept arrays and objects. Default is true
. See strict mode in co-body
. In strict mode, ctx.request.body
will always be an object(or array), this avoid lots of type judging. But text body will always return string type.
detectJSON: custom json request detect function. Default is null
.
1app.use( 2 bodyParser({ 3 detectJSON(ctx) { 4 return /\.json$/i.test(ctx.path); 5 }, 6 }) 7);
extendTypes: support extend types:
1app.use(
2 bodyParser({
3 extendTypes: {
4 // will parse application/x-javascript type body as a JSON string
5 json: ["application/x-javascript"],
6 },
7 })
8);
onError: support custom error handle, if koa-bodyparser
throw an error, you can customize the response like:
1app.use( 2 bodyParser({ 3 onError(err, ctx) { 4 ctx.throw(422, "body parse error"); 5 }, 6 }) 7);
enableRawChecking: support the already parsed body on the raw request by override and prioritize the parsed value over the sended payload. (default is false
)
parsedMethods: declares the HTTP methods where bodies will be parsed, default ['POST', 'PUT', 'PATCH']
.
disableBodyParser: you can dynamic disable body parser by set ctx.disableBodyParser = true
.
1app.use((ctx, next) => { 2 if (ctx.path === "/disable") ctx.disableBodyParser = true; 3 return next(); 4}); 5app.use(bodyParser());
You can access raw request body by ctx.request.rawBody
after koa-bodyparser
when:
koa-bodyparser
parsed the request body.ctx.request.rawBody
is not present before koa-bodyparser
.To use koa-bodyparser
with koa@1.x.x, please use bodyparser 2.x.
1$ npm install koa-bodyparser@2 --save
usage
1const Koa = require("koa"); 2const bodyParser = require("@koa/bodyparser"); 3 4const app = new Koa(); 5app.use(bodyParser()); 6 7app.use((ctx) => { 8 // the parsed body will store in ctx.request.body 9 // if nothing was parsed, body will be an empty object {} 10 ctx.body = ctx.request.body; 11});
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
Found 15/30 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More