heroku-debug
Version:
debugging plugin for the CLI
84 lines (59 loc) • 2.94 kB
Markdown
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![David deps][david-image]][david-url]
[![npm download][download-image]][download-url]
[]: https://img.shields.io/npm/v/co-body.svg?style=flat-square
[]: https://npmjs.org/package/co-body
[]: https://img.shields.io/travis/cojs/co-body.svg?style=flat-square
[]: https://travis-ci.org/cojs/co-body
[]: https://img.shields.io/coveralls/cojs/co-body.svg?style=flat-square
[]: https://coveralls.io/r/cojs/co-body?branch=master
[]: https://img.shields.io/david/cojs/co-body.svg?style=flat-square
[]: https://david-dm.org/cojs/co-body
[]: https://img.shields.io/npm/dm/co-body.svg?style=flat-square
[]: https://npmjs.org/package/co-body
Parse request bodies with generators inspired by [Raynos/body](https://github.com/Raynos/body).
```bash
$ npm install co-body
```
- `limit` number or string representing the request size limit (1mb for json and 56kb for form-urlencoded)
- `strict` when set to `true`, JSON parser will only accept arrays and objects; when `false` will accept anything `JSON.parse` accepts. Defaults to `true`. (also `strict` mode will always return object).
- `queryString` an object of options when parsing query strings and form data. See [qs](https://github.com/hapijs/qs) for more information.
- `jsonTypes` is used to determine what media type **co-body** will parse as **json**, this option is passed directly to the [type-is](https://github.com/jshttp/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](https://github.com/jshttp/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](https://github.com/jshttp/type-is) library.
more options available via [raw-body](https://github.com/stream-utils/raw-body#getrawbodystream-options-callback):
```js
// 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'] });
```
This lib also supports `ctx.req` in Koa (or other libraries),
so that you may simply use `this` instead of `this.req`.
```js
// 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);
```
MIT