Skip to content

Beginner · How the web works · topic 1 of 64 · 20 min

Browser, server, URL and HTTP

Explanation

A website is a set of files kept on a computer called a server. Your browser asks the server for those files using an address called a URL, and the two talk using rules called HTTP. The browser then turns the files into the page you see.

Two computers talking

Every time you open a website, two computers talk. Your phone or laptop runs a browser (Chrome, Firefox, Safari, Edge). Far away, another computer called a server keeps the files of the website. The browser asks; the server answers.

Think of it like this: Think of a restaurant. You (the browser) read the menu and ask the waiter for a dish. The kitchen (the server) cooks it and sends it back. HTTP is the polite way of ordering that both sides understand.

The URL: the address of a page

A URL (Uniform Resource Locator) is the full address of one thing on the web. It has parts, and each part has a job.

output
https://www.irctc.co.in/nget/train-search?from=NDLS

https://          the protocol (secure HTTP)
www.irctc.co.in   the domain (which server)
/nget/train-search  the path (which page on that server)
?from=NDLS        the query string (extra details for the page)
The parts of a URL, using a railway booking site as the example

A domain like irctc.co.in is a name people can remember. A system called DNS (Domain Name System) turns that name into an IP address, the number of the server, just like your phone turns a contact name into a mobile number.

HTTP: the rules of the conversation

HTTP (HyperText Transfer Protocol) is the set of rules for asking and answering. The browser sends a request with a method, such as GET (please give me this page) or POST (please take this form data). The server sends back a response with a status code and the content.

Status codeMeaningWhen you see it
200 OKSuccessThe page loaded normally
301 / 302MovedThe site sends you to a new address
404 Not FoundNo such pageA wrong or old link
500 Server ErrorThe server brokeA bug on the website side

HTTPS is HTTP with encryption (secret code). Nobody between you and the server can read or change the data. Every real site today, especially anything with a login or payment, must use HTTPS.

What the browser does with the answer

  1. It reads the HTML file and builds the page structure.
  2. It sees links to CSS, JavaScript and images, and asks the server for each of them.
  3. It applies the CSS to style the page.
  4. It runs the JavaScript to make the page interactive.
  5. It paints the final result on your screen.

Front-end developers write the files that run in the browser: HTML, CSS and JavaScript. Back-end developers write the code that runs on the server. This course is about the front end.

javascript
const address = new URL('https://www.irctc.co.in/nget/train-search?from=NDLS');
console.log(address.protocol); // 'https:'
console.log(address.hostname); // 'www.irctc.co.in'
console.log(address.pathname); // '/nget/train-search'
console.log(address.searchParams.get('from')); // 'NDLS'
JavaScript can split a URL into its parts for you
Tip: Look at the lock icon next to the address bar. If a site asks for a password or OTP and has no HTTPS, do not type anything.
Careful: A URL can look real but be fake (for example, irctc-booking-offer.xyz). Always check the domain part carefully before you log in or pay.

Watch the lesson

Browser, server, URL and HTTP · 1/6

What happens when you open a website?

Welcome! Let us see what really happens when you open a website on your phone.

Prefer a video by a teacher? Find free videos on “how the web works browser server http explained for beginners” on YouTube ↗

In real life: Checking a PNR status

When you check a train PNR status, your browser sends a GET request to the railway server with your PNR number in the URL or form. The server looks up the booking and sends back an HTML page with status 200. If you mistype the page address, the server answers 404 instead.

Practice (0/3 done)

Task 1 · Code · Javascript

Write a function getDomain(url) that returns only the domain (hostname) of a URL. Example: getDomain("https://www.irctc.co.in/nget/train-search") returns "www.irctc.co.in". Tip: new URL(url).hostname does this.

Task 2 · Code · Javascript

Write a function statusGroup(code) that returns "success" for codes 200 to 299, "redirect" for 300 to 399, "client error" for 400 to 499 and "server error" for 500 to 599.

Task 3 · Practice

Open any three websites you use (for example a news site, a shopping site and a government site). For each one, write down its protocol, domain and path, and say whether it uses HTTPS.

Quick quiz

Question 1

1.What is a server?

Question 2

2.In https://shop.example.in/cart, which part is the domain?

Question 3

3.What does status code 404 mean?

Question 4

4.What does the S in HTTPS add?

Question 5

5.What does DNS do?

Read more (free)

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.