Last active
August 29, 2015 14:01
-
-
Save edwin-bluekite/cd6b6bf336a48c8f01e6 to your computer and use it in GitHub Desktop.
Nipple post and get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. I'm doing a post request to a resource | |
// 2. I read SSE url for the creation procces of the resource is readed in the link header of the response | |
// 3. I run a GET to that url an try to stream the SSE to stdout | |
var parse = require('parse-link-header'); | |
var Nipple = require('nipple'); | |
Nipple.post('resourceurl.com/myresource',{payload:somedata}, function (err1, res1, payload1) { | |
Nipple.read(res1, function (err1, body) { | |
link =parse(res1.headers.link); | |
Nipple.get(link.sse.url,{ headers:{accept:'text/event-stream'},downstreamRes: process.stdout },function(err2,res2,payload2){ | |
console.log(payload2); | |
console.log(res2.headers); | |
res2.pipe(process.stdout); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment