Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bimedia-fr/restify-jsonstream-bodyparser


https://github.com/bimedia-fr/restify-jsonstream-bodyparser

Last synced: 23 days ago
JSON representation

Awesome Lists containing this project

README

        

Restify jsonstream body parser
==============================

When using `server.use(restify.bodyParser()`, content is buffered being passed through to restify bodyParser.

With very large content, this quickly becomes a bottleneck, hanging restify thread while reading data.

This library allow to manually bypass the default bodyParser behaviour to avoid blocking the main event loop, by providing a stream (or JSON stream) instead.
This is to the user of the plugin to define if the content will be processed as a stream or as an object.
All other requests are left unchanged.

## Usage

### Setting
```javascript
server.use(require('restify-jsonstream-bodyparser')());
```

### Sample
```javascript
server.post({
url: '/',
streamer: {
pattern: '*'
}
}, function (req, res, next) {
req.body.pipe(es.writeArray(function (err, content) {
res.send(err ? 400 : 200, content);
}))
.on('end', res.end);
});
```

## Options
As for any restify middleware, you can pass `options`.
Those options will get forwarded to the default `bodyParser` if used.