🧠 1. What is the Client–Server Model?
The Client–Server Model is a simple way computers communicate over the internet.
Think of it like a restaurant:
Role | Example | What It Does |
---|---|---|
Client | You (the customer) | Sends requests (“I’d like a pizza”) |
Server | The kitchen | Prepares and sends back what you asked for (“Here’s your pizza”) |
In web apps, this communication happens using HTTP (Hypertext Transfer Protocol).
HTTP is the “language” both the client and server use to talk.
🔗 2. What is HTTP?
HTTP defines how messages are sent and received between a client (like Chrome, Firefox, or a mobile app) and a server (like Google’s or Amazon’s computers).
Every website visit is an exchange of requests and responses:
Client (Browser) → sends a Request (e.g., “Show me the homepage”).
Server → sends a Response (e.g., “Here’s the homepage HTML file”).
Client → GET /index.html HTTP/1.1
Server → HTTP/1.1 200 OK
<html>Welcome!</html>
⚙️ 3. How Web Apps Work (Step by Step)
Let’s walk through what happens when you open https://www.example.com:
🖥️ Step 1: The Client Sends a Request
Your browser sends a GET request:
GET /index.html HTTP/1.1
Host: www.example.com
🗄️ Step 2: The Server Processes the Request
A web server (like Apache, Nginx, or Node.js) receives it and prepares a response — either by:
Returning a file (like index.html)
Or asking a backend app (e.g., built in Spring Boot, Django, or Express.js) to generate it dynamically.
📨 Step 3: The Server Sends a Response
The server replies with:
HTTP/1.1 200 OK
Content-Type: text/html
<html><h1>Welcome!</h1></html>
🌐 Step 4: The Browser Displays the Page
Your browser reads the HTML, then fetches more resources (CSS, JavaScript, images).
All of this happens through multiple HTTP requests and responses.
🧩 4. Example: A Simple To-Do List Web App
Component | Example | Role |
---|---|---|
Client (Frontend) | React web app | Displays the to-do list and handles user actions |
Server (Backend) | Spring Boot REST API | Stores and retrieves tasks |
Database | PostgreSQL | Saves the actual task data |
Example Flow
You click “Add Task”.
Browser sends:
POST /api/tasks
Content-Type: application/json
{ "task": "Buy milk" }
Server saves the task and responds:
HTTP/1.1 201 Created
{ "id": 1, "task": "Buy milk", "done": false }
Browser updates the visible list instantly — now you see “Buy milk”.
🧠 5. What is State?
In web development, state means the current data or condition of your app — what the user is seeing or interacting with at a given moment.
Examples of State:
- Which user is logged in
- What items are in your shopping cart
- Whether dark mode is on or off
- The list of tasks currently displayed
Each time you refresh the page, move to a new one, or log out, your state may change or reset — unless it’s managed carefully.
🔄 6. State Management in Web Apps
Because HTTP is stateless (it forgets everything after each request), web apps must manage state themselves.
💬 “Stateless” means:
Each HTTP request is independent.
The server doesn’t automatically remember you between requests.
So web apps use state management techniques to keep track of users, preferences, and data.
⚙️ Ways to Manage State
Method | Where Stored | Used For | Example |
---|---|---|---|
Cookies | Browser | Small user data, like login sessions | Set-Cookie: sessionId=abc123 |
Sessions | Server | Server stores user info; browser keeps a session ID | Used for login systems |
Local Storage / Session Storage | Browser | Frontend-only state (preferences, temporary data) | localStorage.setItem("theme", "dark") |
JWT (JSON Web Token) | Browser & Server | Securely keeps user identity between requests | Used in modern APIs |
Frontend State Management Libraries | Browser memory | Handles app-level UI data | React’s Context, Redux, or Flutter’s Provider |
🧭 Example: Login with State
- You log into a website. → Browser sends username and password via POST.
- Server verifies them and creates a session or JWT token.
- Server sends this token to the browser. → Browser saves it in cookies or localStorage.
-
Next time you visit a protected page, your browser includes the token in the request header:
Authorization: Bearer <token>
Server checks the token, confirms your identity, and serves your personalized content.
This way, your “logged-in” state is maintained even though HTTP itself is stateless.
🧩 7. Visualization of the Full Cycle
[ Browser (Client) ]
↓ HTTP Request (GET /tasks)
[ Web Server (Backend) ]
↓ Reads database, prepares response
↑ HTTP Response (JSON Data)
[ Browser Updates UI ]
↓
State Updated (New task shown)
📖 8. Summary
Concept | Meaning |
---|---|
Client | The user’s device/browser that requests data |
Server | The program that processes requests and sends back data |
HTTP | The communication language between client and server |
Stateless Protocol | HTTP doesn’t remember previous interactions |
State | The current condition/data of the web app |
State Management | The methods used to maintain continuity between HTTP requests |
💡 In Simple Terms
- The client asks, the server answers.
- HTTP is their shared language.
- Because HTTP forgets, we use state management (cookies, sessions, tokens, local storage, etc.) to make web apps feel continuous — like you’re always “logged in” or “in the same place.”
Top comments (0)