co-body-qjson
v0.0.0
Published
request body with qjson parsing for co
Downloads
8
Maintainers
Readme
co-body-qjson
inspired by cojs/co-body.
Installation
$ npm install co-body-qjson
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.returnRawBody
when set totrue
, the return value ofco-body
will be an object with two properties:{ parsed: /* parsed value */, raw: /* raw body */}
.jsonTypes
is used to determine what media type co-body will parse as json, this option is passed directly to the type-is library.formTypes
is used to determine what media type co-body will parse as form, this option is passed directly to the type-is library.textTypes
is used to determine what media type co-body will parse as text, this option is passed directly to the type-is library.
more options available via raw-body:
Example
// application/qjson
var body = yield parse.qjson(req);
// explicit limit
var body = yield parse.qjson(req, { limit: '10kb' });
Koa
This lib also supports ctx.req
in Koa (or other libraries),
so that you may simply use this
instead of this.req
.
// application/qjson
var body = yield parse.qjson(this);
License
MIT