Skip to content

Instantly share code, notes, and snippets.

@d13 d13/XmlPoster.js
Last active Apr 1, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.