You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
3 years ago | |
|---|---|---|
| .. | ||
| lib | 3 years ago | |
| node_modules | 3 years ago | |
| History.md | 3 years ago | |
| Readme.md | 3 years ago | |
| index.js | 3 years ago | |
| package.json | 3 years ago | |
Readme.md
co-body
Parse request bodies with generators inspired by Raynos/body.
Installation
$ npm install co-body
Options
limitnumber or string representing the request size limit (1mb for json and 56kb for form-urlencoded)strictwhen set totrue, JSON parser will only accept arrays and objects; whenfalsewill accept anythingJSON.parseaccepts. Defaults totrue. (alsostrictmode will always return object).queryStringan object of options when parsing query strings and form data. See qs for more information.jsonTypesis used to determine what media type co-body will parse as json, this option is passed directly to the type-is library.formTypesis used to determine what media type co-body will parse as form, this option is passed directly to the type-is library.textTypesis 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/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);
// text/plain
var body = yield parse.text(req);
// either
var body = yield parse(req);
// custom type
var body = yield parse(req, { textTypes: ['text', 'html'] });
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);
// text/plain
var body = yield parse.text(this);
// either
var body = yield parse(this);
License
MIT