var Client = require('node-rest-client').Client;
var client = new Client();
module.exports = {
getWeatherStatus: function() {
var messageData = "";
client.get("http://api.openweathermap.org/data/2.5/weather?q=Pune&appid=123234234234243242", function (data, response) {
console.log(JSON.parse(data));
messageData=data;
});
//how to set the response of that rest call to this messageData object
return messageData;
}
}
this method getWeatherStatus should return the rest response in json format.
Open for totally different suggestion to implement this kind of scenario. My basic requirement is to use this REST call response and send to other functions.
I think you are facing difficulties to deal with with callbacks,
In the method
getWeatherStatus
, instead of returning the result, you should pass it to a callback function once the treatment is done.If really you are required to return, galk.in answer seems to be a possible way.
Otherwise, check this out,
So you may call getWeatherStatus in such way,
As suggested, Promise are also a good alternative. but it is still async.