Request–Response Cycle
Request–Response Cycle
Every interaction on the web follows a simple pattern called the request–response cycle.
This cycle is the core of how web applications work.
What is the Request–Response Cycle?
The request–response cycle describes how a client and server communicate.
- The client sends a request
- The server processes the request
- The server sends back a response
- The client renders the result

This cycle happens every time you interact with a website.
Step-by-Step Flow
Let’s break the cycle into clear steps.
Step 1: Client Sends a Request
The process begins when the client (usually a browser) sends a request.
- Request includes method, path, headers, and optional body
- Example: loading a page or submitting a form
Step 2: Server Receives the Request
The server receives the request and prepares to handle it.
- Validates the request
- Routes it to the correct handler
Step 3: Server Processes the Request
The server executes the necessary logic.
- Runs application code
- Interacts with databases
- Calls external APIs if needed

Step 4: Server Sends a Response
After processing, the server sends back a response.
- Includes status code, headers, and body
- Can return HTML, JSON, or other data

Step 5: Client Renders the Response
The client receives the response and displays it.
- HTML is rendered
- CSS styles the page
- JavaScript adds interactivity

Real-World Example
When you open a homepage:
- Browser sends a GET request
- Server processes the request
- Server returns HTML
- Browser renders the page
All of this happens in milliseconds.
Why This Matters
Every framework you’ll use follows this cycle:
- Flask maps requests to functions
- FastAPI handles structured API requests
- Django manages the full lifecycle
Understanding this flow makes debugging and building applications much easier.
Summary
- The request–response cycle is the foundation of the web
- Clients send requests and servers return responses
- The browser renders the final result
In the next lesson, you’ll learn about HTTP methods and how different types of requests are used.