Block 51: HTTP Basics & GET Requests
Understand HTTP and make your first API call with requests.
Concepts
- HTTP concepts: URL, method, status codes, headers
- requests.get(url) and response object
- response.status_code, response.text, response.json()
- Using try/except for network errors
Code Examples
See exercise below.
Exercise
Call a public API (e.g., Open-Notify ISS location or Random User). Print the JSON response. Print the status code and confirm it's 200 before using the data.
Homework
What is the difference between a 200, 404, and 500 status code? Give a real-world analogy.