vukoa-bodyParsePath
process request format for vukoa or koa2, base on co-body. support 'from-data', 'x-www-form-urlencoded', 'raw' type body.
Install
npm install vukoa-bodyparsepatch
Usage
var Koa = ;var bodyParsePatch = ; var app = ;app; app;
Options
-
parsePatch: parser will only parse when parsePatch is true, it will create ctx.request.query and ctx.request.fields
-
enableTypes: parser will only parse when request type hits enableTypes, default is
['json', 'form']
. -
formLimit: limit of the
urlencoded
body. If the body ends up being larger than this limit, a 413 error code is returned. Default is56kb
. -
jsonLimit: limit of the
json
body. Default is1mb
. -
textLimit: limit of the
text
body. Default is1mb
. -
strict: when set to true, JSON parser will only accept arrays and objects. Default is
true
. See strict mode inco-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
.app; -
extendTypes: support extend types:
app; -
onerror: support custom error handle, if
koa-bodyParsePatch
throw an error, you can customize the response like:app; -
disableBodyParser: you can dynamic disable body parser by set
ctx.disableBodyParser = true
.
app;app;
Raw Body
You can set enableTypes: ['text'] you will get
- if raw body can transfer Json, you will get ctx.request.rawBody and ctx.request.fields = JSON.parse(ctx.request.rawBody)
- else you can only get ctx.request.rawBody