Skip to content

Latest commit

 

History

History
26 lines (16 loc) · 1.03 KB

08 Dad API.md

File metadata and controls

26 lines (16 loc) · 1.03 KB

Lab 08: Dad Joke API

Use the Dad Joke API to get a dad joke and display it to the user. You may want to also use time.sleep to add suspense.

Part 1

Use the requests library to send an HTTP request to https://icanhazdadjoke.com/ with the Accept header as application/json. This will return a dad joke in JSON format. You can then use the .json() method on the response to get a dictionary. Get the joke out of the dictionary and show it to the user.

response = requests.get("https://icanhazdadjoke.com", headers={
    'Accept': 'application/json'
})

Part 2

Add the ability to "search" for jokes using another endpoint. Create a REPL that allows one to enter a search term and go through jokes one at a time.

response = requests.get(f"https://icanhazdadjoke.com/search?term=${search_term}", headers={
    'Accept': 'application/json'
})