Manuals / Python / Chapter 9

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 progress
64%

Step 1 of 3

GET request

httpx.get(url) or with Client() for connection reuse. response.raise_for_status() on errors.

GET requestDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →GET requestdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

import httpx

resp = httpx.get("https://jsonplaceholder.typicode.com/users", timeout=10.0)
resp.raise_for_status()
users = resp.json()
assert len(users) == 10

Do 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.