Simple Requests

Jed Rembold

April 10, 2026

Is it only Wednesday?

Quick Announcements

  • Expect Midterm 2 results back on Monday
  • Grade Reports coming
  • Don’t forget about Enigma!
    • It is all you now!
    • Sections will meet next week, but will work with dictionaries
  • I’m in a 3 hour meeting this afternoon, so email or Discord is probably best if you have questions

Daily LO’s

  • How do computers send messages back and forth?
  • What is an API, and how can they be useful?
  • How can we send and interpret GET requests?
  • How can we send and interpret POST requests?

Group Problems

Problem 1: Funny Requests

  • This is a coding problem. Work in pairs or trios on a single computer, and discuss your algorithm/approach before you write any code!
  • The domain + endpoint: http://www.official-joke-api.appspot.com/jokes/random will return JSON with a random joke.
  • Use the requests library to make a GET request to this URL
  • Process the result to JSON
  • Print the setup, then pause and wait for the user to press the enter key before printing the punchline.

Problem 2: Showing Your Age

  • Swap who is typing!
  • The site Agify.io offers an API that can be accessed at https://api.agify.io?name={your name here}
  • Write a function that loops over all the first names in your group, inserts them into the URL, requests the result, and then prints out the oldest name at the end

Problem 3: Country Data

  • Swap who is typing!
  • The site restcountries.com offers up an endpoint at https://restcountries.com/v3.1/name/{country_name} that returns a large amount of information about a given country
  • Write a function that prompts a user to type in a country name, and then uses the API to print to the screen the number of timezones that intersect that country

Problem 4: Post Introduction

  • Swap who is typing!

  • I’ll be showing a URL on the screen (and I’ll post it to Discord)

  • Create a payload dictionary that includes the following fields:

    • "name": Your first name
    • "year": fresh/sophomore/junior/senior
    • "fun_fact": Some fun fact about you!
  • To attach your payload as JSON, you need to include it with the json keyword argument:

    requests.post(|||URL|||, json=|||your dict|||)
  • Look up at the screen as soon as you send it! You should see it pop up!

D&Demo!

Spell Data

  • There is an API for all the 5ed D&D information at https://www.dnd5eapi.co
  • Suppose I wanted to grab all the information about all the available spells
  • Looking at the documentation, that isn’t available from just a single endpoint
  • How could I use multiple API calls to get the information that I want?
// reveal.js plugins // Font Awesome Characters