So or at a place where we have our search term in here and it's really time to go ahead and make an 2
API request so let's do a little bit of investigation on the API that we're going to use to fetch this 3
weather data in my browser. 4
I'm going to open up a new tab and I'm going to navigate to open weather map dot org slash forecast 5
five or so open weather maps or forecast five. 6
If you can't find it that way you can also just search for open weather map forecast API and it's probably 7
going to be one of the first results up on here. 8
OK. 9
So this is what we're looking for. 10
This is a API that we can use to grab forecasts and weather data in the next five days for a particular 11
city. 12
Basically exactly what we want here. 13
So this is a free API while we do have to sign up for it. 14
It is completely free and we do have to sign up for it to get a actual API so we can make a request 15
to the server here. 16
This endpoint right here this by city name is in point that we're going to end up using. 17
So you can see here me dial up the font size a little eyes and big you can see the general format of 18
the requests that we need to make. 19
We're going to make a request to API open weather mapped out or data 2.5 forecast and then we've got 20
our query string here which is everything after the question mark and the part that we really need to 21
supply here is. 22
Q equals. 23
Which basically means queery is the city name Khama country code. 24
So pretty straightforward pretty you know simple endpoint here. 25
We really just got to hit this address right here with a particular city name. 26
And we should get the weather data that we really care about. 27
They've got a sample request right here that we can click on. 28
I'm going to do that and you can see that it's a forecast for London. 29
But in the U.S. So not London in the U.K. for I have no idea why they did this. 30
It's like London in Texas or something like that something weird. 31
Anyways it's going to click that link open up and a new tab. 32
You'll notice that this is SML. 33
We're not going to work with SML. 34
We're gonna end up working with Jaison. 35
So the response that we get back is going to look a lot more like this. 36
You can view the Jaison if you want by just deleting that SML part and then you are l. 37
But if you don't have a URL for or excuse me a Jaison formatter is probably going to end up a little 38
bit ugly here. 39
So if yours is showing up ugly you might want to go back to just looking at the Exham else. 40
Right now we're just going to look at this response for a little bit. 41
So you know if you want to just check out my screen here and no problem whatsoever. 42
All right. 43
So again this is the response for a query for the City of London which again I'm telling you I'm pretty 44
sure it's in Texas not not in the UK. 45
Anyways let's check out the response here at the very top level. 46
We have a city object and the city returns the name of the city that we just search for. 47
So this is actually really important right here because we might have a user's search for some city 48
that doesn't exist or they might misspell it in some fashion. 49
And so it's actually really important to make sure that we get back from the server a confirmation of 50
you know hey I think you meant London is is this actually what you meant. 51
Right. 52
Maybe we left off an oh. 53
Or is this me an and on at the end so I'm going to delete that and let's see what happens now. 54
So we still got London so it's pretty darn intelligent the searching here which is going to be very 55
nice for us. 56
So anyway as the very top level we have the city object which gives us the name and also gives us some 57
coordinates the longitude and latitude and this is pretty important we'll come back to these coordinates 58
later on in the course next if we scroll down just a little bit here we get this list object and the 59
list is an array of objects. 60
So you can see if I hover over this right here we've got just about from up here to down here is a single 61
entry in that array. 62
And in this array there are many many many many such objects totally identical. 63
So what these objects are are they are snapshots of weather data. 64
Three hours at a time. 65
So you'll see this. 66
This is time stamped right here. 67
So for 2016 January 3rd at 0 0 0 the weather in London is expected to be 271 degrees and that's Kelvin 68
not you know Fahrenheit or Celsius. 69
If you don't if you're not familiar with Kelvin it's just a different unit for temperature. 70
You know you can google how to convert from Kelvin to Celsius or Fahrenheit if you like. 71
Anyways the temperature at you know basically midnight right here is going to be 200 71 degrees and 72
then three hours later. 73
So you can see 1 0 3 at 3 a.m. The temperature's going to be 268. 74
And then at 6:00 a.m. It's going to be 267 and so on and so on and so on five days worth of that data 75
. 76
So this list right here is really the prime unit you know the data that we really care about for a search 77
that we get back we really care about what the temperature the humidity and the pressure are in all 78
those three properties sit inside of this main object. 79
OK. 80
So we've got kind of a better idea of what's going on with this response here. 81
We'll come back to the response in the future and talk a lot more about how we're going to pluck out 82
all the different little pieces of data in here that we need. 83
So I'm not going to close this response just yet. 84
You know I'm going to keep it open a little bit so we can reference it again in the future. 85
OK. 86
So that's pretty much the end point that we're going to use. 87
Now we have to do is sign up for it just so we can get our API. 88
If you notice in the response over here the documentation doesn't actually stated very clearly. 89
But it did include a app I.D. right here which is basically are the API key that we're going to need 90
. 91
This is a public key right here. 92
You know if you want to play it risky you could try using this key. 93
But really I recommend you sign up for your own account and get your own API key. 94
So let's do that now. 95
Back to the documentation. 96
I'm going to click on sign up 97
and then I'm going to just put in the User Name of you know I don't ascribe or own five 98
my e-mail 99
and then a password 100
and then right away I get dumped at a kind of like an Account settings page and it says you've sign 101
it successfully. 102
Fantastic. 103
And if I scroll down to a little bit here you'll see that right here on this page. 104
They really know what we really care about right. 105
We just care about the API key. 106
So you can double click the key right here and then copy it. 107
And we're going to save this key right away so we don't lose it. 108
I'm going go back over to my code editor. 109
I'm going to open the actions folder click on index us and we're going to save this key as Konst API 110
underscore key. 111
And then inside of a string we'll paste our key semi-colon. 112
Ok cool. 113
So this is the API key that we're going to make use of when we make the actual request. 114
Let's go ahead and continue in the next section.