I have a Meteor method that goes around http.get. I am trying to return the results from this http.get to the returned method in order to use the results when calling the method.
I can not make it work.
Here is my code:
(In the shared folder)
Meteor.methods({ getWeather: function(zip) { console.log('getting weather'); var credentials = { client_id: "string", client_secret: "otherstring" } var zipcode = zip; var weatherUrl = "http://api.aerisapi.com/places/postalcodes/" + zipcode + "?client_id=" + credentials.client_id + "&client_secret=" + credentials.client_secret; weather = Meteor.http.get(weatherUrl, function (error, result) { if(error) { console.log('http get FAILED!'); } else { console.log('http get SUCCES'); if (result.statusCode === 200) { console.log('Status code = 200!'); console.log(result.content); return result.content; } } }); return weather; } });
For some reason, this does not return results , even if they exist, and the http call works : console.log (result.content); really logs the results.
(client folder)
Meteor.call('getWeather', somezipcode, function(error, results) { if (error) return alert(error.reason); Session.set('weatherResults', results); });
Of course, here the session variable ends up empty.
(Note that this part of the code seems fine, as it returned appropriately if I hardcoded the return with some dummy string in the method.)
reference
source share