Beginner · How the web works · topic 1 of 64 · 20 min
Browser, server, URL and HTTP
Explanation
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.
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.
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)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 code | Meaning | When you see it |
|---|---|---|
| 200 OK | Success | The page loaded normally |
| 301 / 302 | Moved | The site sends you to a new address |
| 404 Not Found | No such page | A wrong or old link |
| 500 Server Error | The server broke | A 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
- It reads the HTML file and builds the page structure.
- It sees links to CSS, JavaScript and images, and asks the server for each of them.
- It applies the CSS to style the page.
- It runs the JavaScript to make the page interactive.
- 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.
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'Watch the lesson
Browser, server, URL and HTTP · 1/6
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)
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.
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.
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
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.