storage-mule
Version:
The Realtime Framework Cloud Storage Mule utility
34 lines (33 loc) • 848 B
JavaScript
var https = require('https');
module.exports = {
post: function(url, jsonData, callback){
var postdata = JSON.stringify(jsonData);
var profileRequestOptions = {
host: url.host,
port: 443,
path: url.path,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postdata.length
}
};
var restRequest = https.request(profileRequestOptions, function(res){
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function(){
if(res.statusCode >= 200 && res.statusCode < 300){
callback(null, body)
} else {
callback('Remote serever error ('+res.statusCode+'): ' + body);
}
});
}).on('error', function(e){
callback('Can not connect to remote server');
});
restRequest.write(postdata);
restRequest.end();
}
};