Create handy HTTP GET function
poxip opened this issue · comments
Michal Proszek commented
Currently HTTP GET request are performed by clumsy http.get() function, that needs to write a lot of the same code. For instance:
http.get(url, function (response) {
var responseParts = [];
response.setEncoding('utf8');
response.on('data', function (chunk) {
responseParts.push(chunk);
});
response.on('end', function () {
var data = responseParts.join('');
console.log(data)
});
}).on('error', function (e) {
debug.error('HTTP ' + e.message);
});
So to avoid code duplications we can create a new, asynchronus nibo.utiles.http.get(url, callback) function.