The Request-Response Cycle
Understand how every HTTP API conversation works — from client to server and back.
Every time you click a button in a web app, your browser sends a message to a server. The server processes it and sends a reply. This is called the request-response cycle — and it's the foundation of every web API you'll build.
Client (browser/app)
│
├─► HTTP Request → Server (your FastAPI app)
│ │
└─◄ HTTP Response ←─────┘As a backend engineer, you write the server side — the code that receives requests, does the work, and sends back responses.
An HTTP request has four key parts:
GET /users/42 HTTP/1.1
Host: api.myapp.com
Authorization: Bearer eyJhbGc...
Content-Type: application/json
{"name": "Alice"}- Method — what action (GET, POST, PUT, DELETE)
- Path — the resource URL (
/users/42) - Headers — metadata (auth token, content type)
- Body — data sent with the request (optional, mainly for POST/PUT)
Which part of an HTTP request specifies the action to perform?
- AThe method (GET, POST, PUT, DELETE)
- BThe path
- CThe body
- DThe Authorization header
The response your server sends back:
HTTP/1.1 200 OK
Content-Type: application/json
{"id": 42, "name": "Alice", "email": "alice@example.com"}- Status code — 200 means success; 404 means not found; 500 means server error
- Headers — metadata about the response
- Body — the actual data returned (JSON for APIs)
A client sends a request for a user that doesn't exist. What status code should the server return?
- A404 Not Found
- B200 OK
- C500 Internal Server Error
- D201 Created
Complete the status code range: 2xx = success, 4xx = client error, ___xx = server error
A client sends POST /users with a valid JSON body. The server creates the user. What status code should the response be?
- A201 Created
- B200 OK
- C204 No Content
- D202 Accepted
Where does data travel in a GET request?
- AIn the URL as query parameters (e.g., /users?page=2)
- BIn the request body as JSON
- CIn the Authorization header
- DGET requests cannot send data