The Request-Response Loop
architect, critique, revise, codeModule 1: The Request-Response Loop
Goal: Understand how web servers receive instructions and return data over HTTP.
What you need to know first
Client-Server Model: The client (e.g., a browser, a mobile app, or a command-line tool) makes a Request. The server (your running Python script) listens for requests, processes them, and returns a Response.
HTTP (HyperText Transfer Protocol): The format used to send requests and responses. Think of an HTTP request like sending a physical letter in an envelope:
- The Envelope (Headers & Metadata):
- Method (Verb): E.g.,
GET(fetch data) orPOST(create new data). This is the instruction. - Path (Endpoint): E.g.,
/tasks. This is the delivery address. - Headers: Small metadata details written on the envelope (e.g.,
Content-Type: application/jsontells the server the letter inside is formatted as JSON).
- Method (Verb): E.g.,
- The Letter Inside (The Body): The actual payload data being sent (e.g., the details of a new task).
- The Response (The Return Mail): The server sends back its own envelope with a Status Code (like
200 OKmeaning success, or404 Not Foundmeaning wrong address) and a response body.
The SOLO idea
Even for the simplest endpoints, we never bypass the planning loop. Jumping straight to coding without defining requirements leads to ad-hoc structures. We follow the exact sequence: /architect → /critique → /revise → /code.
Lab 1: Your First Web Server
Estimated AI conversations: 2-3
-
Create a file called
main.pyin your project folder. -
Step A: Plan the Endpoint. Open Copilot Chat and type:
Follow #file:workflows/architect.md — Plan a basic FastAPI server in main.py. It needs a single GET endpoint at
/that returns a JSON message:{"status": "online"}. The plan should detail how the FastAPI instance is initialized and how uvicorn runs the app. -
Step B: Challenge the Plan. In the same conversation, type:
Follow #file:workflows/critique.md — Critique the plan you just produced. Are there port conflicts or path issues?
-
Step C: Revise the Plan.
Follow #file:workflows/revise.md — Revise the plan to address the critique findings (like specifying a standard local port like 8000).
-
Step D: Implement.
Follow #file:workflows/code.md — Implement the server in
main.pybased on the finalized plan. -
Verify the code matches this standard pattern:
from fastapi import FastAPI import uvicorn app = FastAPI() @app.get("/") def read_root(): return {"status": "online"} if __name__ == "__main__": uvicorn.run("main:app", port=8000, reload=True) -
Run your server:
python main.pyYou should see logs indicating uvicorn is running on
http://127.0.0.1:8000. -
Inspect the HTTP traffic: Open a second terminal window and make a request using
curl:- Mac/Linux/Windows:
Thecurl -i http://127.0.0.1:8000/-iflag forces curl to show the headers returned by the server. Notice lines like:HTTP/1.1 200 OK(Status code)content-type: application/json(Data format header){"status":"online"}(Response body)
- Mac/Linux/Windows:
-
Close the server in your terminal with
Ctrl+C. -
Commit your changes:
git add main.py git commit -m "Module 1: simple GET server running" git push
Checkpoint
Create checkpoint_01.md:
- Paste the raw headers printed by your
curl -icommand. - Explain in 1 sentence what the
200inHTTP/1.1 200 OKrepresents.