Lab 11: Web APIs
Solutions
Lab Setup
- Find a partner
- Use CyberDuck to SFTP into one of your accounts on the
cs.wellesley.edu
server - On the server, navigate to the
cs111/Downloads
folder - Download the
lab11
folder to your Desktop (by dragging and dropping it from the CyberDuck window) - Open Canopy and load the
lab11
folder in the Canopy File Browser pane
Web APIs Overview


Steps to generate a query-driven web page with results:
- Using the
requests
module, make a request for data from a web API. - Convert the resulting data (a JSON string) into a dictionary, using the
json
module. - Study the data to understand how it's structured.
- Iterate through the data to extract the information of interest.
- Fill a HTML template with the extracted information (using
jinja2
). - View the resulting HTML page in a browser (using
webbrowser
).
Note: the HTML template files will render as web pages in the browser. To see the underlying HTML code, view the source code (in Chrome, View > Developer > View Source)