Skip to content

Instantly share code, notes, and snippets.

@xsyn

xsyn/gist:2593326

Created May 4, 2012
Embed
What would you like to do?
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