Block 52: Query Parameters & Headers
Pass data to APIs using query parameters and request headers.
Concepts
- params dict for query strings
- headers dict for Auth, Content-Type, User-Agent
- Pagination: fetching multiple pages
- requests.Session() for reuse
Code Examples
See exercise below.
Exercise
Call a search API (e.g., Open Library or REST Countries) with a query parameter. Print number of results. Write a loop that fetches 3 pages of paginated results and collects all records.
Homework
Why might an API return different results for the same URL without vs with a User-Agent header? Tuesday