1.0.1 • Published 11 years ago
co-better-body v1.0.1
co-body
Parse request bodies with generators inspired by Raynos/body.
Installation
$ npm install co-bodyOptions
Available via raw-body:
limitnumber or string representing the request size limit (1mb for json and 56kb for form-urlencoded)Available via qs:
depthnumber representing the parsed object maximum hierarchy depth, default5delimiterstring or regex representing the query string delimeter, default&arrayLimitnubmer representing the maximum array size or -1 to disable arrays, default20
Example
// application/json
var body = yield parse.json(req);
// explicit limit
var body = yield parse.json(req, { limit: '10kb' });
// application/x-www-form-urlencoded
var body = yield parse.form(req);
// either
var body = yield parse(req);Koa
This lib also supports ctx.req in Koa (or other libraries),
so that you may simply use this instead of this.req.
// application/json
var body = yield parse.json(this);
// application/x-www-form-urlencoded
var body = yield parse.form(this);
// either
var body = yield parse(this);License
MIT