URI, URN, and URL (Protocol, Domain, Port, Path, Query Strings, Fragments)

Aykhan Nazimzada
6 min readDec 13, 2020

In this article, I will talk about URIs, URLs and URNs because I see a lot of confusion between this three. In fact, I used to confuse between them, and they caused me a lot of headache, and I don’t want you to go through that. Learning about these three terms and the difference between them can be quite useful on the long run. So, what do these three acronyms stand for? What do they mean? What is the difference between them? And why does it matter? Let’s start by defining each one of them.

The URI stands for “Uniform Resource Identifier”. It is a string of characters used to identify a resource on the internet either by location or by name or both. For example, let’s say we want to get to a friend. His name is “Lorem Ipsum”. Ok, that’s not a name but anyway. And his address is “7083 Columbia Street, Woonsocket, RI 02895”, random things. Actually, we need to use either his name or his address. Think of the URI as using the name or the address to identify the person we want to get to. And of course, we can use both at the same time. Whether we use just one or both, in both cases, it is a URI. It is a way to identify the resource. We will come back to the URI later.

Now, the URL stands for “Uniform Resource Locator”. It is pretty self-explanatory, right? It is also a string of characters, but it refers to just the address, just the location of the resource. It is the most used way to locate resources on the web. For example, in our case, we can identify our friend by just using his location.

URN in its place stands for Uniform Resource …… Can you guess that? Yeah, name. “Uniform Resource Name”. Now, this should be obvious to you it is the name of the resource. Again, in our case. if we want to locate our friends using a URN, we will use his name “Lorem Ipsum”. I really loved this male name.

URIs can specify the name and the location of the source we are looking for as we say the one of them or both at the same time. URLs use just the location while URNs indicate just the name then, technically a URI is either a URL or a URN, right? Therefore, every URL and every URN is a URI. Well, that’s true because back in the mid-90s, in the creation of web identifiers, URIs were split into two classes; that specify the location and those that specify the name. And to avoid the confusion about whether a URI is specifying the name or the location. URIs that specify the location were called URLs, “Uniform Resource Locators”. That’s what we use in web browsers actually when we want to get a web page. URIs that specify the name we’ll call URNs. And, Identifiers that specify both the name and the location is called, of course, URI.

Since two or more resources can have the same name, it is ineffective to use URNs to identify and locate resources. Thus, almost all the time, we use URLs to do that, and because we use URLs most of the time, let’s talk about them in a little more detail.

In order to allow clients to request resources from servers, HTTP messages need to be sent to the server holding the URL. Well, how can we send an HTTP message? We do that by typing the URL in the browser and hitting the “Enter”. Let’s see how a URL looks like.

URL consists of two required components; the protocol used to connect, and the domain or the IP address to connect to. As you may know, URL has other than these information but that’s optional such as the path which locate the file or the directory in the server, and you can also see the port and other components that we will see in a few.

The first part is the protocol we are using which is of course HTTP or HTTPS. If we are looking for resources on the web, we can use different protocols, for example, if we want to share files on the internet, we use the FTP protocol. The second part is the domain. The domain is the name that the domain name server gives you a unique IP address so that we can use either the name or the IP address. For example, “mywebsite.com” has the IP address “111.222.33.444”. The domain in the URL is case-insensitive.

An optional attribute is the port. if there is any, it should be after the domain preceded by a colon (:). You may wonder what a port is. Simply, port is a type of software connection point used by the TCP/IP protocol and the connecting computer. Think of that as two persons want to meet, and two parallel walls are between them. Each wall has the same number of doors as the other one, and its door is facing its opposite vis-à-vis (face-to-face) and lead just to it. In order to meet, the two persons should open the same door in each wall. This is the same principle as the port in a URL. By specifying the port number, we are telling the server from which ports our request is coming and from which should be received. By default, every protocol has its default port number, so if we didn’t specify the port number, it’s actually the same as using the default, and it doesn’t appear on the URL. For example, the HTTP default port is 80. If we want to connect to the server via different port, we should specify that.

https://mywebsite.com:888/register.php

In this case, we are trying to connect through the port 888. The next part of the URL is the path. This is a familiar concept to anyone who has ever used a computer file system. This is a way to locate the resource on the server.

https://mywebsite.com/products/product.php

There can be other parts which are query strings and fragments. Query Strings are a way of passing information from the client to the server such as entering information in user form input. They are preceded by a question mark (?) and encoded as key value pairs delimited by an ampersand (&) symbol. And here is an example of that:

https://mywebsite.com/signup?fullname=Lorem&lastname=Ipsum

Fragments are always at the end of the URL. You can identify a fragment by the hash (#) symbol before it. They are used as a way of requesting a portion of a page. Browsers will see the fragment tag in the HTML code and scroll the website down to it. For example, this is a URL that contains the fragments from the Wikipedia website:

https://en.wikipedia.org/wiki/Web_developer#External_links

To sum up, we’ve seen that we use URIs, URLs or URNs to identify resources. URIs can specify the address or the name of the resource or both at the same time. We usually use URLs to identify resources, and a URL consists of required components which are the protocol and the domain and optional ones such as port, path, query strings and fragments. So, there you have it! No headaches anymore! I hope you find this article useful, and you’ve learned something from it. Till the next article, keep learning and stay tuned!

--

--