Core question: How do a client and a server actually talk to each other step-by-step?

🍏 Tutor’s Notes

In the previous lesson, we met the two main actors on the internet: the Client and the Server. Now, how do they actually communicate?

Every single action you take online—clicking a link, liking a photo, logging into your bank account, or searching for a song—follows a strict, predictable rhythm called the Request ↔ Response Cycle:

  1. The Client sends a Request: It asks the server for information or asks it to perform an action.
  2. The Server processes the Request: It does the work behind the scenes (checks security, talks to the database, runs calculations).
  3. The Server sends back a Response: It replies with the result (either the requested data or an error message explaining what went wrong).

The Golden Rule: In standard web communication, the server never speaks first. It sits quietly waiting. A conversation only happens when a client initiates a request, and once the server sends its response, that single cycle is complete.

Step 1: Anatomy of a Request (What the Client Sends)

When you click a button or type a web address, your browser doesn't just shout across the internet. It packs a neatly formatted digital envelope called an HTTP Request.

Every request envelope has four key parts:

Part Analogy What It Does Example
1. URL (Endpoint) The street address on the envelope Tells the internet which server and which specific resource you are asking for. https://example.com/profile
2. Method (Verb) The intent sticker ("Order", "Return", "Inquiry") Tells the server what action you want to perform on that resource. GET, POST, PUT, DELETE
3. Headers The return address & special handling notes Extra metadata about the request—what browser you're using, your preferred language, or your login token. Accept-Language: en-US
4. Body (Payload) The letter inside the envelope (Optional) The actual data you are sending to the server. Empty when just reading a page; full when submitting a form. {"username": "alex", "Bio": "Dev"}

The 4 Most Common Request Methods (Verbs)

Step 2: What Happens in the Middle? (Inside the Server)

Once your request travels across the internet and arrives at the server, the server doesn't just bounce an answer back blindly. In a fraction of a second (often 20 to 200 milliseconds), the server:

  1. Reads the envelope: Checks the URL, the Method (GET, POST, etc.), the Headers, and the Body.