|
5 years ago | |
---|---|---|
.. | ||
History.md | 5 years ago | |
Readme.md | 5 years ago | |
index.js | 5 years ago | |
package.json | 5 years ago |
JSON pretty-printed response middleware. Also converts node object streams to binary.
$ npm install koa-json
pretty
default to pretty response [true]param
optional query-string param for pretty responses [none]spaces
JSON spaces [2]Always pretty by default:
var json = require('koa-json');
var app = koa();
app.use(json());
app.use(function *(next){
this.body = { foo: 'bar' };
});
yields:
$ GET /
{
"foo": "bar"
}
Default to being disabled (useful in production), but togglable via the query-string parameter:
var app = koa();
app.use(json({ pretty: false, param: 'pretty' }));
app.use(function *(next){
this.body = { foo: 'bar' };
});
yields:
$ GET /
{"foo":"bar"}
$ GET /?pretty
{
"foo": "bar"
}
MIT