Beginner · How the web and backends work · topic 2 of 54 · 25 min
Clients, servers, IP addresses and URLs
Explanation
Client and server
A client is any program that sends a request: Chrome on your laptop, the Swiggy app on your phone, or even another server. A server is the program (and the computer it runs on) that receives the request and sends back a response. This way of working is called the client-server model.
One server can answer thousands of clients at the same time. The client starts the talk; the server waits and answers. A server never knocks on your phone first in plain HTTP.
IP addresses and domain names
Every computer on the internet has an IP address (Internet Protocol address). It is a number like 142.250.183.14 (the older IPv4 style) or a longer one like 2404:6800:4009:80b::200e (the newer IPv6 style). Computers find each other using these numbers.
Numbers are hard for people to remember, so we use domain names like irctc.co.in or google.com. DNS (Domain Name System) is a big phone book of the internet that turns a domain name into an IP address.
Ports
One computer can run many server programs at once. A port is a number from 0 to 65535 that says which program should get the message. Web traffic uses port 80 for HTTP and port 443 for HTTPS. When you build a backend on your laptop, it often listens on port 3000 or 8080.
The parts of a URL
| Part | In https://shop.example.in:8080/products/42?colour=red#reviews | Meaning |
|---|---|---|
| Protocol (scheme) | https | The rules to talk with: http or https |
| Domain (host) | shop.example.in | Which server; DNS turns it into an IP address |
| Port | 8080 | Which program on that server (optional; 443 is the default for https) |
| Path | /products/42 | Which thing on the server you want |
| Query | ?colour=red | Extra options as name=value pairs, joined with & |
| Fragment | #reviews | A spot inside the page; it is never sent to the server |
const url = new URL('https://shop.example.in:8080/products/42?colour=red&size=m#reviews');
console.log(url.protocol); // 'https:'
console.log(url.hostname); // 'shop.example.in'
console.log(url.port); // '8080'
console.log(url.pathname); // '/products/42'
console.log(url.search); // '?colour=red&size=m'
console.log(url.hash); // '#reviews'
console.log(url.searchParams.get('size')); // 'm'HTTPS: the locked version of HTTP
HTTP sends messages as plain text. Anyone on the same Wi-Fi or network path could read them. HTTPS is HTTP inside an encrypted tunnel (called TLS), so only the client and the server can read the messages. The padlock in the browser bar means HTTPS is on. Every real website and API should use HTTPS.
Watch the lesson
Clients, servers, IP addresses and URLs · 1/6
Every web request has two sides. The client asks, and the server answers.
Prefer a video by a teacher? Find free videos on “how the internet works dns ip address url explained for beginners” on YouTube ↗
In real life: Searching trains on IRCTC
You type irctc.co.in. Your phone asks DNS for the IP address of that name. It then opens a secure HTTPS connection to that IP on port 443. When you search for trains from Delhi to Jaipur, the app builds a URL with a path and a query, and the server reads those parts to know what you want.
const search = new URL('https://trains.example.in/search?from=NDLS&to=JP&date=2026-11-02');
console.log(search.hostname); // trains.example.in
console.log(search.pathname); // /search
console.log(search.searchParams.get('from')); // NDLS
console.log(search.searchParams.get('to')); // JPPractice (0/3 done)
Write a function urlParts(address) that returns an object { protocol, host, path, query }. protocol is without the colon ("https"), host is the hostname without the port, path is the pathname, and query is the search part without the "?" ("" when there is none).
Write a function getQuery(address, name) that returns the value of the query parameter called name, or null when it is not in the URL. Encoded values like New%20Delhi must come back decoded ("New Delhi").
Write a function portOf(address) that returns the port as a number. If the URL has no port written, return the default: 443 for https and 80 for http.
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.