Consume REST API in Node.js + cURL

1

I know there are several packages in Node to consume REST API but I need some packages that use cURL . For some reason (which I did not discover) I can not authenticate with existing ones.

I've tried link and link .

    
asked by anonymous 11.11.2015 / 10:27

1 answer

2

So I converted a client in PHP to Node.js .

link

It's a wrapper (I do not know how it would look in pt) in this package which in turn is a wrapper in the cURL .

Usage looks something like this:

var host = 'https://api.budgetvm.com/v2/dns/record';
var key = 'some___key';
var domain_id = 'some___id';

var rest = require('vps-rest-client');
var client = rest.createClient(key, {
  verbose: false
});

var post = {
  domain: domain_id,
  record: 'test.example.net',
  type: 'A',
  content: '111.111.111.111'
};

client.post(host, post).then(function(resp) {
  console.info(resp);

  if (resp.success === true) {
    client.get(host + '/' + domain_id).then(function(response) {
      console.info(response);
      client.close();
    });
  } else {
    client.close();
  }
}).catch((err) => console.info(err));
    
11.11.2015 / 10:27