Transius.1895:

I’m curious – I’ve looked through the list of API wrappers and only found one for Node.js, but it looks horribly outdated. I’ve Googled around and found at least one additional wrapper, but it looks incomplete at best, and it is also mostly untouched as of late.

Now, before I go on with creating my own wrapper, is anyone aware of any relatively up to date Node.js API wrappers that just didn’t get added to the list on the wiki?

Bormotun.9568:

What for wraper? All you need is http get request:
https://nodejs.org/api/http.html#http_http_get_options_callback

http.get('http://www.google.com/index.html',{
                headers: {
                    Authorization: "Bearer " + key
                }
            }, (res) => {
  console.log(`Got response: ${res.statusCode}`);
  // update your models with received data res.data

}).on('error', (e) => {
  console.log(`Got error: ${e.message}`);
});

aliem.3412:

It’s not so simple as it seems without library (you need to consume the res stream and listen to errors … and of course clean up the mess) but with request or fetch is pretty simple as in:

request (callback pattern):


request.get('url',
            {
                headers: {
                    Authorization:
                        `Bearer ${new Buffer('my_long_key').toString('base64') }`
                }
             }, (err, res) => { /* consume the request */ });

fetch (promise):


function check(res) {
    if (res.status > 300) {
        throw new Error(`My fancy error for ${status}`)
    }
    return res;
}

function json(res) {
    return res.json()
}

fetch('url',
      {
          headers: {
              Authorization:
                  `Bearer ${new Buffer('my_long_key').toString('base64') }`
              }
       })
.then(check)
.then(json)
.then((body) => doSomething(body))
.catch((err) => handleError(err))
...;