koa-parse-json

1.0.1 • Public • Published

koa-parse-json

Parse json request body, generator style.

It seems that similar modules don't provide sane stack traces, or simply ignore errors. Because this one is completly generator-based, it provides proper stacktraces on parse error.

Install

$ npm install koa-parse-json

Usage

var koa = require('koa');
var body = require('koa-parse-json');
 
var app = koa();
 
app.use(body());
 
app.use(function* () {
  this.body = this.request.body;
});

API

body(opts)

Returns a koa middleware, that can parse JSON request body. It stops reading after opts.limit bytes, and throws 413, if Content-Length doesn't match with request length, 400 is throwed.

Default opts.limit is 1MB.

License

MIT

Package Sidebar

Install

npm i koa-parse-json

Weekly Downloads

6

Version

1.0.1

License

MIT

Last publish

Collaborators

  • lennon