The following function calls Rest Web Service and gets some value, but while returning the result does not contain any value.
var http = require('http'); var options = { host : 'localhost', // here only the domain name http://localhost:8080/RestService/rest/message/getItems // (no http/http !) port : 8080, path : '/RestService/rest/message/getItems', // the rest of the url with parameters if needed method : 'GET' // do GET };
function getService() {
http.request(options, function(res) {
console.log('STATUS1: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
return chunk;
});
}).end();
}; console.log(" Return Value --> "+getService());