Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streaming api full json comaptible #2

Open
kilianc opened this issue Oct 19, 2011 · 0 comments
Open

streaming api full json comaptible #2

kilianc opened this issue Oct 19, 2011 · 0 comments

Comments

@kilianc
Copy link
Owner

kilianc commented Oct 19, 2011

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:

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

{
    "random1": { /* item content */ },
    "random2": { /* item content */ },
    "random3": { /* item content */ },
    "randomN": { /* item content */ },
    ...
}
@ghost ghost assigned kilianc Apr 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant