Lesson 39 of 49 beginner

How the Internet Works

The Web Explained Simply

Open interactive version (quiz + challenge)

Real-world analogy

The internet is like a library. You (the client/browser) walk up to the front desk and ask the librarian (HTTP) for a book. The librarian goes to the back shelves (the server), finds or prepares your book (processes the request), and brings it back to you (the response). URLs are like the catalog system — they tell you exactly where every book lives!

What is it?

The internet is a global network of connected computers that communicate using rules called protocols. When you visit a website, your browser (client) sends an HTTP request to a server, which processes it and sends back a response (usually HTML, CSS, JS, or JSON data). APIs let programs exchange data, and DNS translates domain names to IP addresses.

Real-world relevance

Every app on your phone uses these concepts. When you scroll Instagram, your phone (client) sends HTTP GET requests to Instagram's servers, which respond with JSON data (posts, likes, comments). Your phone then displays that data as the feed you see. Understanding this flow is fundamental to building any web application.

Key points

Code example

// How the internet works — step by step:

// 1. You type a URL in your browser
// URL: https://api.example.com/users/1

// 2. DNS translates the domain to an IP address
// "api.example.com" → "93.184.216.34"

// 3. Your browser sends an HTTP GET request
// GET /users/1 HTTP/1.1
// Host: api.example.com

// 4. The server processes the request and responds
// Status: 200 OK (meaning "success!")

// 5. The response comes back as JSON data:
const response = {
  "id": 1,
  "name": "Alex",
  "email": "alex@example.com",
  "role": "developer"
};

// HTTP Methods — the 4 main actions:
// GET    → Read data    (fetch a user profile)
// POST   → Create data  (sign up a new user)
// PUT    → Update data  (change your email)
// DELETE → Remove data  (delete your account)

// A real API response with multiple items:
const users = [
  { "id": 1, "name": "Alex", "role": "developer" },
  { "id": 2, "name": "Sam", "role": "designer" },
  { "id": 3, "name": "Jo", "role": "manager" }
];
console.log(users.length); // 3 users

Line-by-line walkthrough

  1. 1. Comment: Walking through how the internet works
  2. 2.
  3. 3. Comment: Step 1 — the user action
  4. 4. The URL you typed — this is the 'address' of the data you want
  5. 5.
  6. 6. Comment: Step 2 — DNS lookup
  7. 7. DNS converts the human-readable domain into a numeric IP address
  8. 8.
  9. 9. Comment: Step 3 — the browser sends a request
  10. 10. This is the actual HTTP request format — GET means 'give me data'
  11. 11. The Host header tells the server which website you want
  12. 12.
  13. 13. Comment: Step 4 — the server responds
  14. 14. 200 OK is the status code meaning everything worked
  15. 15.
  16. 16. Comment: Step 5 — the response body
  17. 17. This is the JSON data the server sent back
  18. 18. Opening the response object with curly braces
  19. 19. The user's unique ID
  20. 20. The user's name
  21. 21. The user's email
  22. 22. The user's role
  23. 23. Closing the object
  24. 24.
  25. 25. Comment: The four main HTTP methods
  26. 26. GET reads data — like viewing a profile
  27. 27. POST creates new data — like signing up
  28. 28. PUT updates existing data — like editing your bio
  29. 29. DELETE removes data — like deleting a post
  30. 30.
  31. 31. Comment: A JSON array with multiple objects
  32. 32. Opening the array with a square bracket
  33. 33. First user object — Alex is a developer
  34. 34. Second user object — Sam is a designer
  35. 35. Third user object — Jo is a manager
  36. 36. Closing the array
  37. 37. Accessing the length property — arrays know how many items they hold

Spot the bug

// Trying to fetch data from an API
GET https://api.example.com/users

// Expected response:
{
  name: Alex,
  age: 25
}
Need a hint?
Look at the JSON format — is something missing around the values?
Show answer
JSON requires string values to be wrapped in double quotes! Fix: {"name": "Alex", "age": 25}. The number 25 doesn't need quotes, but 'Alex' does because it's a string. Valid JSON always uses double quotes, never single quotes.

Explain like I'm 5

Imagine you're sending a letter. You write the letter (your request), put an address on it (the URL), drop it in the mailbox (the internet), and it goes to the post office (DNS) which figures out where it should go. The letter arrives at someone's house (the server), they read it, write a reply, and send it back to you. That round trip is how the internet works!

Fun fact

The first website ever created is still online! Tim Berners-Lee created it in 1991 at CERN. You can visit it at info.cern.ch — it's a simple page of text and links about the World Wide Web project. The entire internet grew from that one humble page!

Hands-on challenge

Open your browser and go to: jsonplaceholder.typicode.com/users — this is a free, public API! You'll see real JSON data with fake users. Notice the structure: curly braces for objects, square brackets for arrays, key-value pairs. This is what APIs look like under the hood!

More resources

Open interactive version (quiz + challenge) ← Back to course: Full-Stack Playbook