A Basic Interview Question: Can You Explain Every Part of a URL?
Let’s break down URLs piece by piece
An ad campaign for a flashy new web service grabs your attention. You unlock your phone, choose your favorite internet browser, and type in the URL as best you can remember it. After a second or several (depending on your phone carrier) — voila, a fresh webpage has loaded before your eyes!
It’s a tale as old as time (or at least the late 1990s), but can you explain how that crucial component — the URL — functions? If you want to be a web developer, this is a very basic concept you must know. Let’s dive in.
What is a URL?
URL is an acronym for Uniform Resource Locator. As the name suggests, a URL details a specific location for a unique resource on the Web and serves as the tool browsers use to retrieve any published resource at that location. URLs are commonly compared to a street address, with each section of the URL serving as a different piece of the address and representing different information. Let’s take a look at this example URL and break it down piece by piece:
http://: This is the scheme, which identifies the protocol the browser must use to request the data at the URL (protocols are rules for sending data over the Internet). There are many schemes, but http (without SSL) is most common alongside https (with SSL), the secured version of the HTTP protocol used for sensitive data. The colon
: is the scheme separator and the forward slashes
// establish the start of the domain name.
pickles.com: This is the domain name (also known as the host) which indicates the intended host or web server that is being requested. Each component of the host name separated by a period is a domain. On the right (.com) is the domain suffix or top-level domain, and the domain to the left (www.) is the second-level domain or sub-domain. Domain suffixes vary greatly and include .org, .net, and region-specific suffixes like .gov.au.
:80: This is the port, which indicates the gate used to access resources on the intended web server. When a browser contacts a server, it might use a well-known port number. Well-known port numbers are assigned to internet protocols. For example, the standard port for HTTP is 80 (HTTPS is 443). When standard ports are in use, this part of the URL is usually omitted (given the commonness of HTTP, this is often the case). Otherwise, a port must be included. The colon here also acts as a separator.
/pickles/index.html: This is the path, which indicates the path to the specific resource on the server that the browser wants to access. The forward slashes serve as separators to maintain URL hierarchical syntax.
?type=sweet&size=small: This is a query string, which always begins with a question mark
? followed by one or more parameters to enable the server to return specific content. Parameters are key/value pairs (type=sweet) separated with the
& symbol (&size=small). Every web server handles parameters according to their own unique rules.
#Summertime_Sweet_Pickles: This is called the anchor, also known as the fragment identifier, which always begins with a hash
# followed by text. This section represents a specific location on a webpage that the user will be taken to, as if “anchoring” the URL there. If the URL retrieves an HTML page, a fragment identifier can indicate a subsection of the page, using the correlating ID of the subsection.
Putting It All Together
Not every URL contains every element detailed above but together they make up the core components of a URL. Using each label as its respective section and the proper separators it might be helpful to visualize a URL like this:
There are other parts and other rules for URLs but these are the URL components that you will see most often and that you should be prepared to be able to explain. Now go ace that interview!