Consider the following code in Node. The function of web service is a web services provider with input and output parameters. Since this is only an example, there are no input parameters:
var request = require('request');
function mywebservice() {
request.get(
'http://www.google.com',
function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
return body
}
I need the return the body variable because the web service has to return the variable, but I cannot find a way with making the variable known in the return statement. Even with promises the value of body would be in a function and would not know how to copy to the variable body.
I have already read: How do I return the response from an asynchronous call? and I have not found a solution to get the variable in the response of my webservice.