Correct way of processing an http.request response
Posted: 26 Mar 2015 12:40
Hello!
I'm writting a module that makes a call to an URL using http.request method. I need to process the result of the request but I'm not sure the right way to do it. I've tried this:
but I'm not getting any log (nor success, nor error). I've also tried with a callback function:
But it's not working either. Finally, I tried this:
And it's the way I'm getting something. Is this the correct way of doing it? It looks strange for me not be able to execute a callback function.
I'm writting a module that makes a call to an URL using http.request method. I need to process the result of the request but I'm not sure the right way to do it. I've tried this:
Code: Select all
http.request({
method: 'GET',
url: encodeURI(myURL),
success: function (response) {
console.log("Success!");
},
error: function () {
console.log("ERROR!!");
}
});
Code: Select all
http.request({
method: 'GET',
url: encodeURI(myURL),
}, function (response) {
console.log("Callback!");
});
Code: Select all
var response = http.request({
method: 'GET',
url: encodeURI(myURL),
});
console.log(JSON.stringify(response));