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.
So I converted a client in PHP
to Node.js
.
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));