Video Pending

Created by Zed A. Shaw Updated 2024-02-17 04:54:36
 

53: Getting Data from APIs

In this exercise you'll access the Application Programmer Interface (API) I use for my learncodethehardway.com website. In web development an API is usually a combination of the following:

  1. A web server that you can access with the HTTP protocol. You used HTTP when you used urllib to get the beer production PDFs from the ttb.gov website. HTTP is also what your browser uses to display the web application to you.
  2. This web server responds in some data format that's easily parsed. This is what differentiates a PDF from an API. Sure, you're getting data on beer production from ttb.gov but you have to parse that data out of a PDF. An API gives you the data ready to go in a format that loads directly into your application with no manual parsing.
  3. A higher level API will provide features to discover how the API works automatically. This is a more advanced feature of APIs but many of them will have an initial URL that describes the API, and then each piece of data will describe what's allowed and link to related elements. There is no official standard on how this is done, but if it's available it's nice to have.

I use an API in my web application that conforms to #1 and #2, but only partially #3 since I don't actually care if other people can dynamically figure out how to use my API. #3 on this list is a common practice since private APIs are made for a specific application written by the API owners, while public APIs are intended for anyone to use and discover. I chose my private API because many times those are the most useful because other people are too lazy to reverse engineer them.

Please do not download the raw video or HTML files for the course since that will most definitely crush my little web server. This also vioalates TOS. You are only allowed to access the public (unauthenticated) JSON API described here.
Previous Lesson Next Lesson

Register for Learn Python the Hard Way, 5th Edition (2023-2024)

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.