#100DaysOfWeb in Python Transcripts
Chapter: Days 17-20: Calling APIs in Flask
Lecture: Day 4: Your Turn - What did we learn?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 And that was calling APIs in Flask. Congratulations on making it to the end of the four days. If you are just starting your fourth day
0:10 or just finished the videos on that go ahead, check out the README file to see what you have to do on this day
0:16 otherwise, let's run through some of the key stuff that we've learnt. So these were the two APIs that we touched on. We used the Chuck Norris API
0:28 and we used the Pokemon API. Now, with the Chuck Norris one we actually learnt how to parse objects from our app.route, from our Flask application
0:42 over through to our template. Now, the first thing we had to do was create the route for our Chuck webpage.
0:51 Then we took the actual joke that we pulled from the API and we assigned it to a joke object. And then what we did, was we took that joke object
1:01 and returned it to the Flask template as an object named joke. That's why you can see the two colors there the yellow and the blue.
1:10 The joke in blue was the object that came from the API from that function, again, Chuck joke.
1:19 And the yellow joke object was the one that was sent across to our Flask template. It is important to note that the object returned
1:28 to the template can have a different name it's just this format here of having it named the same is something you'll see more often than not.
1:38 Next we wanted to look at handling post methods. This was within our Pokemon API's chapter and what we did was, we had to specify right at the start
1:49 of our app.route for the Pokemon webpage we actually had to specify that it could handle post request and if you remember from the video
1:57 we actually got an error because we didn't tell it we could post. Now, given we are allowing post requests
2:06 we don't want anything to just be able to come back to our application, to our backend. So what we have there, is we have a request method
2:14 that will only respond or do something if it's a post-request and the idea of pokecolour is in the request form.
2:25 That is, the post request that comes through has the ID of pokecolour. And that way we know that that is the only data
2:32 we are going to take, if there is data that is sent through as a post. We then took that data that was sent through assigned it to the color object
2:44 and then we used that color object to query the API using the get poke colors function. And finally, after getting all of the data back
2:53 that we need, we parse it off back to the Flask template just like we did in the Chuck Norris API with pokemon equals pokemon.
3:03 Now, within that get pokecolours function we parsed through the color that someone enters when they use the website.
3:11 Now we did this so we could customize the request that went off to the website that went off to the API because we wanted users to be able to request
3:21 a specific color. So you can't hard-code every color into the request; you simply just take that variable, that object
3:29 that people enter in and append it onto the end. And that's what we did that with color.lower
3:35 we made sure that it was lowercase so that it actually works with the API. If there is any capitals in there, it was going to fail.
3:43 And finally, we take that data back we convert it to JSON and we assign it to the poke data object. And that was it, that was pretty much everything
3:54 that we did in the course. It doesn't seem like there's a lot there but as you know, there was quite a bit that we covered
4:00 so feel free to go back over the videos again. If you're on Day 4, look at the README file and see what it is that you have to do.
4:08 Once you are done, head on over to the next chapter and keep calm and code in Python


Talk Python's Mastodon Michael Kennedy's Mastodon