CodeRigor

LESSON

Fetch and export a deterministic category report

Compose encoded requests, bounded reads, validated pages, safe retries and category concurrency into a working local CLI.

The artifact is a useful small integration: fetch paginated order fixtures and produce category counts and integer-cent totals. It uses the helpers you have tested rather than hiding failures inside a large CLI function.

The download includes a real loopback API server, a standard-library transport, the working model, a capstone starter, fixtures, tests and setup/cleanup instructions. The default command starts its own server on an ephemeral local port and closes it afterward. No remote service account is required.

Compose the boundaries
start / 3
Independent category jobs each perform an encoded, bounded, validated and paginated request chain, then feed a deterministic report.
Compose the boundaries
Independent category jobs each perform an encoded, bounded, validated and paginated request chain, then feed a deterministic report.

Within a category, encode category and cursor as query values, request /orders, retry only under the explicit policy, validate each page and merge stable identities. Reject a returned item with the wrong category instead of quietly mixing it into another total.

Across categories, use bounded_map and asyncio.to_thread for the synchronous transport. The shared stop flag is checked before new request work; setting it in finally helps collectors stop after failure or cancellation. A thread already blocked in I/O may finish later. The CLI’s asyncio.run waits for executor shutdown; this is still cooperative ownership, not forceful socket termination.

Python
groups = [("hardware",[{"amount_cents":500}]),("books",[{"amount_cents":125},{"amount_cents":200},{"amount_cents":75}])]
rows = [{"category":category,"count":len(items),"amount_cents":sum(item["amount_cents"] for item in items)} for category,items in sorted(groups)]
print(rows)
print("total cents",sum(row["amount_cents"] for row in rows))

Sort category rows after collection, so caller order and worker completion order do not change the report. Keep money in cents. Identical overlap within a category is deduplicated; repeated ids across different categories fail rather than double-counting conflicting ownership. Include an empty requested category as a zero row.

Run the working CLI and the test suite from the extracted lab. Use the starter model to practice the final composition; it fails until implemented. Failure tests include over-limit bodies, bad content types, schema errors, unsafe retries, cursor cycles and cancellation. The real local server confirms that request encoding and the transport boundary work together.

The desktop transport accepts literal 127.0.0.1 HTTP only, bypasses environment proxy discovery and does not follow redirects. That keeps this reproducible lab local. Boot.dev’s related course is the continuation into broader network communication, DNS, asynchronous HTTP and HTTPS.

Report only after complete success
start / 3
Partial or conflicting data produces an error. A successful report contains sorted requested categories and totals from accepted unique records.
Report only after complete success
Partial or conflicting data produces an error. A successful report contains sorted requested categories and totals from accepted unique records.
Python
import json
report={"categories":[{"category":"books","count":3,"amount_cents":400}],"count":3,"amount_cents":400}
print(json.dumps(report,sort_keys=True,separators=(",",":")))

Finish fetch_report, then run the downloaded integration tests and CLI. Compare the same category set in a different order: the exported JSON should agree. Deliberately trigger a server failure and verify it produces a clear error rather than a partial “successful” report.

Extend with another category or a new deterministic failure fixture. Before changing the client to an external provider, learn its endpoint schema, authentication, rate limits, TLS behavior and retry semantics. Keep hosted grading on supplied exchanges.

Download the complete lab. The archive includes runnable code, tests, fixtures and a README.

Watch & read

Free lectures, talks and readings that cover this skill from another angle. All resources →

Optional HTTP background using Requests. Our original lab uses the standard library and an injected transport; no Requests dependency is required.