Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@d13
Last active April 1, 2016 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d13/eda0f6e068bdf4011025 to your computer and use it in GitHub Desktop.
Save d13/eda0f6e068bdf4011025 to your computer and use it in GitHub Desktop.
Node.js: Simple XML API requests
var request = require('request');
var assign = require('lodash.assign');
var XmlPoster = function(options) {
this.url = options.url;
this.headers = options.headers || {};
};
XmlPoster.prototype.request = function(body) {
var me = this;
var xmlConfig = {
url: me.url,
headers: assign({
'Content-Type': 'text/xml'
}, me.headers),
body: body
};
return new Promise(function(resolve, reject) {
request.post(
xmlConfig,
function (err, response, body) {
if (err) {
reject(err);
} else {
resolve({
response: response,
body: body
});
}
}
);
});
};
module.exports = XmlPoster;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment