I'm working in NodeJs and I'm making a JSONClient request with restify to an API and I want to send the text/event-stream
header in order to suscribe me to the server responses.
A common call to the API without that header looks like this:
var client = restify.createJSONClient({
url: 'http://api.example.com'
});
return client.get('/getResource',
function (err, req, res, obj) {
//Do stuff
}
Doing this I get an answer but it's not the final one, for example I could get "working", "busy" or "doing-something" so I want to suscribe me to the server responses and when the response will finish then "do the stuff I need with the data".
Is there a way to send the headers on a get request (JSONClient) in restify?
I'd tried something like this but seems not to be working
client.headers["content-type"] = 'text/event-stream';
I don't know if I'm been clear enough but I need the equivalent to:
curl -H "accept:text/event-stream" http://api.example.com/getResource
By the way, I'm stuck with restify since I'm using node-workflow.
I want to avoid making polling as possible.