Consume REST API in Node.js + Curl

Asked

Viewed 2,484 times

1

1 answer

2


So I converted a client into PHP for Node.js.

https://www.npmjs.com/package/vps-rest-client

It’s a wrapper (I don’t know what it would be like in pt) in this bundle which in turn is a wrapper in cURL.

The use is something like that:

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));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.