koa-bodyparser
A body parser for koa, express. support json
, form
, text
, multipart
and stream
type body.
Install
Usage
const Koa = require('koa');
const bodyParser = require('http-body-parser');
const app = new Koa();
app.use(bodyParser({
}));
app.use(async ctx => {
ctx.body = ctx.request.body;
});
Options
{
enableTypes: ['json', 'form', 'text', 'multipart', 'stream'],
json: {
limit: 1024*1024,
strict: true,
extendsTypes: []
},
text: {
limit: 1024*1024,
extendsTypes: []
},
form: {
limit: 56*1024,
extendsTypes: []
},
stream: {
limit: 1024*1024
},
multipart: {
limit: 1024*1024
}
}
- enableTypes: parser will only parse when request type hits enableTypes, default is
['json', 'form', 'text', 'multipart', 'stream']
. - encode: requested encoding. Default is
utf-8
. - limit: limit of the body. If the body ends up being larger than this limit, a 413 error code is returned. Default is
56kb
. - strict: when set to true, JSON parser will only accept arrays and objects. Default is
true
. - extendTypes: support extend types, eg:
['application/x-javascript']
Raw Body
You can access raw request body by ctx.request.rawBody