co-body
Parse request bodies with generators inspired by Raynos/body.
Installation
$ npm install co-body
Options
limit
number or string representing the request size limit (1mb for json and 56kb for form-urlencoded)strict
when set totrue
, JSON parser will only accept arrays and objects; whenfalse
will accept anythingJSON.parse
accepts. Defaults totrue
. (alsostrict
mode will always return object).queryString
an object of options when parsing query strings and form data. See qs for more information.
more options available via raw-body:
Example
// application/jsonvar body = parse; // explicit limitvar body = parse; // application/x-www-form-urlencodedvar body = parseformreq; // text/plainvar body = parsetextreq; // eithervar body = ;
Koa
This lib also supports ctx.req
in Koa (or other libraries),
so that you may simply use this
instead of this.req
.
// application/jsonvar body = parse; // application/x-www-form-urlencodedvar body = parseformthis; // text/plainvar body = parsetextthis; // eithervar body = ;
License
MIT