To be able to access the API, we will need to sign up and create an account. Without further ado, let's create an account at http://openweathermap.org/appid:

Click on Sign Up and follow the process. In the end, you'll access a member dashboard with the API tab. You can copy the API key provided:

Now let's check out how to call the API and get results. If we go on to the documentation provided by OpenWeather (http://openweathermap.org/current), you can get an example of an API call:

The URL is composed like this:

The result we get from this call looks like this (you can test yourself):
{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":300,"main":"Drizzle","description":"light intensity drizzle","icon":"09d"}],"base":"stations","main":{"temp":280.32,"pressure":1012,"humidity":81,"temp_min":279.15,"temp_max":281.15},"visibility":10000,"wind":{"speed":4.1,"deg":80},"clouds":{"all":90},"dt":1485789600,"sys":{"type":1,"id":5091,"message":0.0103,"country":"GB","sunrise":1485762037,"sunset":1485794875},"id":2643743,"name":"London","cod":200}
The code provided is in JSON, a format used generally when displaying data. The code is minified, so it is harder to read. Let's use a tool to un-minify it. I used http://unminify.com/. To do that, just paste the code and click on Unminify:
{
"coord": {
"lon": -0.13, "lat": 51.51
}
,
"weather":[ {
"id": 300, "main": "Drizzle", "description": "light intensity drizzle", "icon": "09d"
}
],
"base":"stations",
"main": {
"temp": 280.32, "pressure": 1012, "humidity": 81, "temp_min": 279.15, "temp_max": 281.15
}
,
"visibility":10000,
"wind": {
"speed": 4.1, "deg": 80
}
,
"clouds": {
"all": 90
}
,
"dt":1485789600,
"sys": {
"type": 1, "id": 5091, "message": 0.0103, "country": "GB", "sunrise": 1485762037, "sunset": 1485794875
}
,
"id":2643743,
"name":"London",
"cod":200
}
Now that the code is more, you can see that the data is displayed with an id and a value. We can use whichever we desire. For this exercise, we will pick the following data:
- Average Temperature
- Min Temperature
- Max Temperature
- The description of the weather
- The sunrise and sunset time
Let's get started.