poxip / nibo

Extensible IRC bot written in NodeJS -- NOTE: The project is no longer being developed.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create handy HTTP GET function

poxip opened this issue · comments

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.