kilianc / kilianc/node-apiserver

streaming api full json comaptible

Open
#2 0 comments 0 reactions 1 assignee Claimed by @kilianc View on GitHub
enhancement feature-request
Dominant language
JavaScript
Stars
224
Forks
20
PR merge metrics
No merged PRs in 30d

Description

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 */ },
...
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.