How can I use $resource.get() params correctly or $http.get()

I followed an angular tutorial that uses api.openweathermap.org for the weather app lesson. Because openweathermap.org doesn’t have anymore weather data more than 1 day, I found another website that allows you to have weather data for free more than 1 day.

The problem is that I can’t figure out how to implement the new demo link in the tutorial link, inside $resource.get().

Code for api.openweathermap.org:

With $resource

$scope.weatherAPI = $resource("http://api.openweathermap.org/data/2.5/weather?");
$scope.key = 'sdfdfdsfdsfsdfrtrt';
$scope.weatherResult = $scope.weatherAPI.get({q: $scope.city, appid: $scope.key});

With $http:

var query = city + ', ' + country;
$http.get('http://api.openweathermap.org/data/2.5/weather?', {
	params: {
		q: query,
		appid: key
	}

Output:

openweathermap.org/data/2.5/weather?q=Boston,usa&appid=xddfdfreredfwsere

New link from api.wunderground.com

http://api.wunderground.com/api/xfgfgffgghghrer/forecast/q/CA/San_Francisco.json

My issue is that in openweathermap after ? you can use your params easy, but on wunderground you have a lot of / / to separate the params.

Can someone please tell me how to implement this second link in $resource or $http?

Hi sorin21us, I haven’t used API wunderground before but it looks like all the information is in the url. So rather than append query string parameters, you need to manually put the URL together.

In your $http example:

var normalisedCity = $scope.city.replace(' ', '_');
var url = 'http://api.wunderground.com/api/' + $scope.key + '/forecast/q/' + $scope.country + '/' + normalisedCity + '.json';

and then use the url in your $http call.

$http.get(url)

Hope that helps, happy to answer any questions :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.