D · HTTP · intermediate · Week 4–5 · Chapter 9 of 13
httpx for API calls
Sync httpx for scripts; async httpx pairs with Playwright later. Status codes, JSON bodies, timeouts, basic auth headers.
Path progress64%
Step 1 of 3
GET request
httpx.get(url) or with Client() for connection reuse. response.raise_for_status() on errors.
Example
import httpx
resp = httpx.get("https://jsonplaceholder.typicode.com/users", timeout=10.0)
resp.raise_for_status()
users = resp.json()
assert len(users) == 10Do this now
Fetch jsonplaceholder users. Assert 200 and len(users) == 10.
Was this step clear?
Chapter learning outcomes
- httpx.Client
- GET/POST
- Status codes
- Timeouts and errors
Clear these before you leave
Side quest
Health check script
CLI: check_urls.txt → GET each → print OK/FAIL with status.