Skip to content

Instantly share code, notes, and snippets.

@xsyn
Created May 4, 2012 08:33
Show Gist options
  • Save xsyn/2593326 to your computer and use it in GitHub Desktop.
Save xsyn/2593326 to your computer and use it in GitHub Desktop.
Problem is the response in res.send is undefined.
app.get('/products', function(req, res) {
var Client = http.createClient(80, 'local.10layer.com');
var request = Client.request("GET", '/workers/api/section/products', {'host' : 'local.10layer.com'});
request.addListener("response", function(response) {
var body = "";
response.addListener("data", function(data) { //Add listener for the actual data
body += data; //Append all data coming from api to the body variable
});
response.addListener("end", function() { //When the response ends, do what you will with the data
var response = JSON.parse(body); //In this example, I am parsing a JSON response
console.log(response);
});
});
request.end();
res.send(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment