Call an #ASMX #WebService API using #NodeJS
Here’s a quick example showing how to use NodeJS to call an ASMX .NET webservice: – you need to replace the username with one from your account on RegCheck.org.uk
And you need to npm install xml2js
var http = require(‘http’);
var parseString = require(‘xml2js’).parseString; // npm install xml2jsfunction getHttp(host,path,callback) {
return http.get({
host: host,
path: path
}, function(response) {
// Continuously update stream with data
var body = ”;
response.on(‘data’, function(d) {
body += d;
});
response.on(‘end’, function() {
callback(body);
});
});
}
getHttp(“www.regcheck.org.uk”,”/api/reg.asmx/Check?RegistrationNumber=ukz2955&username=XXXXXXX”,function(data){
parseString(data,function(err,result){
var innerJson = result.Vehicle.vehicleJson;
var oInnerJson = JSON.parse(innerJson);
console.log(oInnerJson.Description);
});
});