Objective & prerequisites
Observe HTTP requests and responses against a small local server. Before starting: basic Python functions, dictionaries, loops, JSON and terminal use. Complete the earlier Git/API/testing workshops if these are unfamiliar. Download and extract the kit into a new practice folder, then open a terminal in the software-kit folder. Python 3.10+ is required; the reference uses only the standard library. Work with the supplied fictional data. These free companion lessons do not change protected course access or award progress or certificates.
python3 --version
python3 -m unittest discover -s tests -vUnderstand the concept
An HTTP route combines a method and path with a documented contract. This actual teaching server binds only 127.0.0.1 on an operating-system-selected port. GET /health describes the lab. POST /v1/summary accepts a closed orders JSON envelope and returns a computed summary without saving anything. POST is used to submit a calculation, not to create a persistent resource, so success returns 200 rather than 201. A socket connection and JSON parsing are separate layers. The server has no accounts, authentication, persistence, TLS, public ingress or service-level promise. Python http.server is not suitable for production; do not bind it to 0.0.0.0, upload it to Aruba as an application service, or send private information.
Worked example
Run python -m dch_orders.service in terminal A and copy its printed port. In terminal B, use the client below, replacing YOUR_PORT with that number. Four fictional source rows return count 4 and total_cents 40000. The client sets a five-second timeout and reads the actual HTTP response. This is different from the earlier pure-function mock: tests start an ephemeral server and send real HTTP requests, then shut it down.
import http.client, pathlib, json
# Replace YOUR_PORT with the port printed by the local service.
port = YOUR_PORT
connection = http.client.HTTPConnection("127.0.0.1", port, timeout=5)
try:
connection.request("POST", "/v1/summary", body=pathlib.Path("orders.json").read_bytes(), headers={"Content-Type": "application/json"})
response = connection.getresponse()
print(response.status, json.loads(response.read()))
finally:
connection.close()Try it yourself
Start the service, request /health, submit orders.json and stop with Ctrl+C. Record the port, response status, Content-Type and decoded total. Try GET /unknown. Explain why receiving a response does not prove the analytical source is complete. Write your expected outcome before running your implementation. Keep the supplied solution unchanged so that you can compare your own reasoning with it.
Worked solution
/health returns 200; a valid summary returns 200 with web 27000 and store 13000; /unknown returns 404. No database or remote account is involved. The automated HTTP suite creates its own port so it does not depend on your manually running server. The bounded teaching service is single-threaded; the timeout limits a body read but is not a production resource-exhaustion defense.
Knowledge check
If the local server returns 200, is it now safe to expose publicly?
Check and explain
No. The result verifies a local fixture. Public deployment requires a separate architecture, authentication/authorization where appropriate, supported server, TLS, operating limits and deployment review.
Evidence & common mistakes
Record the exact command, Python version, observed output and one rejected input. Explain what each check establishes and what it leaves untested. Do not remove validation merely to obtain a passing result. A local passing suite is evidence for these fixtures, not proof of production readiness. Credit the teaching reference and distinguish your own changes. The kit includes an exercise worksheet, a separate worked-solutions document, an API contract, expected results and a capstone rubric.
Authoritative reference
— official reference for the underlying interface. Lesson prose and fictional order examples are original. The teaching HTTP service is loopback-only, stateless and not suitable for production or uploading as a running Aruba service. No cloud account, paid API or registration is required.
Try the activity before reading its reference. Keep your sources, commands and assumptions with your work. Companion activities are unsaved self-practice and do not award a certificate or change lesson progress.