kilianc/node-apiserver — Issue #2: Feature request: streaming api full json comaptible
Author: kilianc
Created: 2011-10-19 12:49:00+00:00
State: open

We should ad a parameter to `responseStreamStart` specifying the kind of input or the start/end stream strings.

The main goal is to make something like this possible:

````javascript

MyApiModule.prototype.testPublic = function(request, response) {

var self = this;

// start/stop strings
self.emit("responseStreamStart", request, response, 200, null, ['{', '}']);
// or json type defined in apimodule.js
self.emit("responseStreamStart", request, response, 200, null, ApiModule.responseStreamTypes.OBJECT);

var myAsyncEventEmitter = new SomethingAsync();

myAsyncEventEmitter.on('data', function(err, item){
self.emit("responseStreamData", request, response, { key: randomKey(), value: item }, false);
}

myAsyncEventEmitter.on('end', function(err, item){
// last object (avoiding trailing commas)
self.emit("responseStreamData", request, response, { key: randomKey(), item: item }, true);
self.emit("responseStreamEnd", request, response);
}
}
````

this should produce a response like this

````javascript
{
"random1": { /* item content */ },
"random2": { /* item content */ },
"random3": { /* item content */ },
"randomN": { /* item content */ },
...
}
````