Course:Internet & Tools/
Lesson

A URL is the address of a resource on the web. Like a postal address tells the mail system where to deliver a letter, a URL tells your browser where to find a webpage, image, or APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. endpointWhat is endpoint?A specific URL path on a server that handles a particular type of request, like GET /api/users.. Understanding how URLs work will help you debug problems, build better APIs, and navigate the web more effectively.

Breaking down a URL

Let's dissect a complete URL piece by piece:

https://www.example.com:443/products/shoes?color=red&size=42#reviews
PartValuePurpose
Protocolhttps://How to communicate
Domainwww.example.comWhich server to contact
Port:443Which door to knock on
Path/products/shoesWhich resource to request
Query?color=red&size=42Extra parameters
Fragment#reviewsWhere to scroll on the page
02

ProtocolWhat is protocol?An agreed-upon set of rules for how two systems communicate, defining the format of messages and the expected sequence of exchanges.: the rules of communication

The protocol tells the browser how to talk to the server:

  • HTTPWhat is http?The protocol browsers and servers use to exchange web pages, API data, and other resources, defining how requests and responses are formatted. = HyperText Transfer Protocol (unencrypted, avoid for sensitive data)
  • HTTPSWhat is https?HTTP with encryption added, so data traveling between your browser and a server can't be read or tampered with by anyone in between. = HTTP Secure (encrypted with SSL/TLSWhat is ssl/tls?Encryption protocols that secure the connection between a browser and a server, preventing eavesdropping on data in transit.)

Always use HTTPS. It protects passwords, personal data, and prevents attackers from intercepting your communication. When you see the lock icon in your browser, you're using HTTPS.

Other protocols you might see

ProtocolUse caseExample
file://Local filesfile:///Users/me/doc.html
ftp://File transfersftp://files.example.com
ws://WebSockets (real-time)ws://chat.example.com
mailto:Email linksmailto:help@site.com
03

Domain: finding the right computer

The domain identifies which server to contact. It's hierarchical, reading from right to left:

www.example.com
└──┬──┘ └──┬──┘ └─┬─┘
   │      │      └── Top-level domain (TLD)
   │      └───────── Domain name
   └──────────────── Subdomain
  • .com = top-level domain (TLDWhat is tld?Top-Level Domain - the last segment of a domain name (.com, .org, .fr), indicating the domain's type or country.), indicates the type of site
  • example = domain name, the registered name
  • www = subdomainWhat is subdomain?A prefix to a domain (api.example.com, blog.example.com) that routes to a distinct service or section of a site., often used for the main website

DNSWhat is dns?The system that translates human-readable domain names like google.com into the numerical IP addresses computers use to find each other. (Domain Name System) translates this human-readable name into an IP addressWhat is ip address?A numerical label (e.g., 172.217.14.206) that identifies a device on a network - DNS translates domain names into IP addresses. that computers understand. You type google.com, DNS tells your browser 172.217.14.206.

Subdomains in practice

Subdomains let organizations organize different services:

SubdomainTypical use
wwwMain website (historical convention)
apiApplication programming interface
blogCompany blog
shopE-commerce section
appWeb application
cdnContent delivery network (images, videos)
04

Port: which door to knock on

Ports are like doors on a building. Each service listens on a specific port. They're usually hidden because browsers use sensible defaults:

ProtocolDefault portWhen you see it
HTTP80Almost never (implied)
HTTPS443Almost never (implied)
Development3000, 8080Local development
Database5432, 3306Direct database connections

You mostly see ports during development: localhost:3000 means "my own computer, port 3000."

05

Path: locating the resource

The path specifies which resource you want on the server:

/products/shoes/nike-air-max

It's like folders on your computer. The server decides what to return for each path. RESTWhat is rest?An architectural style for web APIs where URLs represent resources (nouns) and HTTP methods (GET, POST, PUT, DELETE) represent actions on those resources. APIs use paths to organize endpoints logically:

PathWhat it returns
/usersList all users
/users/123Specific user with ID 123
/users/123/postsPosts by user 123
06

Query parameters: sending extra data

Query parameters let you send additional information to the server:

?color=red&size=42&sort=price

They start with ?, use key=value format, and multiple params are separated by &.

Common use cases:

Use caseExample URL
Search?q=javascript+tutorial
Filters?category=books&price=low
Pagination?page=2&limit=20
Tracking?utm_source=newsletter
Sorting?sort=date&order=desc

URL encoding

Special characters in URLs must be "percent-encoded":

CharacterEncodedWhy
Space%20 or +Spaces aren't allowed
&%26Would confuse query params
=%3DWould confuse key=value
?%3FWould start new query string

Working with URLs in JavaScript

// Parse a URL
const url = new URL('https://example.com/search?q=react&page=2');

console.log(url.protocol);  // 'https:'
console.log(url.hostname);  // 'example.com'
console.log(url.pathname);  // '/search'
console.log(url.search);    // '?q=react&page=2'

// Build a URL programmatically - much safer than string concatenation
const apiUrl = new URL('https://api.example.com/users');
apiUrl.searchParams.set('limit', '10');
apiUrl.searchParams.set('sort', 'name');
console.log(apiUrl.toString());
// 'https://api.example.com/users?limit=10&sort=name'
AI pitfall
AI tools love to hardcode full URLs and build them with string concatenation like ` https://api.example.com/users/${id}?page=${page} . This breaks when you deploy to a different environment (staging, production) and skips encoding special characters. Always use the URL and URLSearchParams` APIs to build URLs safely, and store base URLs in environment variables, not scattered across your codebase.
07

FragmentWhat is fragment?A React wrapper (<></>) that groups multiple elements without adding an extra HTML node to the page.: browser-only navigation

The fragment (everything after #) is special, it's never sent to the server:

https://docs.example.com/guide#installation

The browser uses it for:

  • Jumping to sections on the same page
  • Single-page app routing (React Router, Vue Router)
  • Tab navigation within a page

Because it's browser-only, you can't use fragments to send data to the server. They're purely for client-side navigation.

08

URL best practices

Do:

  • Use HTTPSWhat is https?HTTP with encryption added, so data traveling between your browser and a server can't be read or tampered with by anyone in between. for anything involving passwords or personal data
  • Keep URLs readable and meaningful
  • Use query params for optional filters, not required data
  • URL-encode special characters in values

Don't:

  • Put sensitive data (passwords, APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. keys) in URLs, they get logged by servers and browser history
  • Create extremely long URLs, they break in email clients and some systems
  • Change URLs without redirects, you'll break bookmarks and SEO

09

Quick reference

PartSyntaxSent to server?Example
Protocolhttps://YesHTTPS, HTTP, WS
Domainexample.comYesVia DNS lookup
Port:443Yes80, 443, 3000
Path/products/shoesYesResource location
Query?key=valueYesFilters, search, pagination
Fragment#sectionNoIn-page navigation