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