Every interaction on the internet begins with a URL (Uniform Resource Locator). Whether you are loading an API payload, fetching an image from a CDN, or navigating to a Next.js route, URLs are the universal addressing system of cyberspace. But beneath their familiar surface lies a modular architecture.
##Anatomy of a Web URL
A complete URL can be broken down into six foundational components: the scheme (protocol), subdomain and domain (host), optional port, pathname, search query parameters, and anchor fragment.
"Cool URIs don't change. Good URI design reflects resource hierarchies, not implementation details." — Tim Berners-Lee
// Parsing and inspecting URL components with the Web URL API
const rawUrl = "https://devyalchemist.com:443/blog/understanding-a-url?utm_source=twitter&theme=dark#anatomy";
const parsed = new URL(rawUrl);
console.log({
protocol: parsed.protocol, // "https:"
hostname: parsed.hostname, // "devyalchemist.com"
port: parsed.port, // "443"
pathname: parsed.pathname, // "/blog/understanding-a-url"
searchParams: Object.fromEntries(parsed.searchParams), // { utm_source: "twitter", theme: "dark" }
hash: parsed.hash, // "#anatomy"
});
