Disclosure: This post contains affiliate links. I may earn commission from any sales made or actions taken as a result from users clicking the links on this page.
Table of Contents
We all use many URLs on a daily basis. Sometimes we type them, sometimes we are just redirected to one URL by another. It is interesting to know that most of us think http://google.com or http://facebook.com are just URLs, but only a few know that we can also refer to them as the URI with the “I”. The URI, in fact, is a superset of URL and something called as a URN. We can thus safely conclude that all URLs are URIs. The opposite is not true, though.
Because URI can be a resource’s name or location. But the URL is only the location. A quick real-life example to understand this would be –
Your name, say John is the URN. The place you live, or your address, say #34, Canter Street, is the URL. You can be identified as a unique person with your name or your address. That unique identity is the URI. While your name can be your unique identifier (URI), it can’t be a URL because your name doesn’t help find your location. In other words, URI (which are URN) are not URLs.
Let’s come back to the internet world now. In this article, we will discuss what URL and URI are and then go over a few subtle differences between both.
Before that, if you have ever wondered –
How did URI or URL come into existence? Who created and approved them and on what basis? And why is there a confusion between the two?
Believe me, it is a piece of interesting quick information that you will not regret reading.
You must have certainly heard of W3C (World Wide Web Consortium) and IETF (Internet Engineering Task Force). The www model that we use today was created by W3C founder, Sir Tim Berners-Lee and thereafter W3C defines the web and HTML specifications. W3C is the stakeholder of the definition of URI and URL. The IETF, which is an open international community works on the internet related standards. For this reason, W3C and IETF work in tandem and while IETF gives different definitions for URL and URI, some experts on the web use it interchangeably, and hence the big confusion!
What’s a URI?
URI stands for Uniform Resource Identifier. It could be a name, locator or both. URI can contain URL and URN. However, when the URI is just a name, that means it is not a URL.
URI contains scheme, authority, path, query, and fragment in that same order. Some of the most common URI schemes that we use are HTTP, https, ftp, ldap, mailto, telnet, gopher, news, etc…
The generic URI syntax follows IEFTs RFC 3986.
The syntax is –
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Before I throw some examples for you, I thought it would be nice to know why it is called ‘Uniform’. why not just Resource Identifier?
Uniformity not only allows for different resource identifiers to be used in the same context, but it also allows for a uniform semantic representation of common conventions across the resource identifiers. That also means it is easier to have new resource IDs introduced without interfering with existing ones.
Now to the examples –
https://hackr.io/blog - this is the typical URI that we know of and call it as URL.
How about this one?
The above is a URI but not a URL. It identifies a resource. A resource can be anything. It need not be a web service always. It can be an image, a document or a collection of several resources.
In gist, URI can be
Now that we know what URI is, the URL should be pretty clear too. Always remember – URI can contain URL, but the URL specifies only the address of a resource. As the name says, it is a ‘Locator’. URI is thus broader than the URL.
URL contains the following information –
- The protocol that is used for accessing the resource – HTTP: https: ftp: etc…
- Location of the server using IP address or domain name – for example, hackr.io is the domain name. http://198.152.1. 1 – here a resource is located using its IP address (126.96.36.199)
- The port number on the server. For example, http://localhost:8080, where 8080 is the port. It is not mandatory to mention the port.
- The exact location in the directory structure of the server. For example – http://hackr.io/blog is the exact location if a user wants to go to the blog section of the website.
- An optional fragment identifier. For instance, https://www.google.com/search?ei=ARDsXO-1EL7az7sPvbWigAo&q=URL where q=URL is the query string user typed.
How do you identify whether something is URI vs URL?
Well, if you want to know if that ‘something’ is URI or URL, you should always mark it as a URI because all URLs are URIs.
Head to head comparison: URI vs URL
Let’s do some side by side comparison so that whatever we have discussed so far is reinforced and you will not get confused about using URI and URL wrong ever again!
|Identifier of a resource||Locator of a resource|
|Superset of URL||Type of URI|
authority = [userinfo@]host[:port]
[protocol]://www.[domain_name]:[port 80]/[path or exaction resource location]?[query]#[fragment]
|The scheme can be anything – protocol, name or specification, etc…||The scheme is always a protocol like HTTP, https, ftp, LDAP etc…|
|The main purpose of URI is to identify a resource and distinguish it from other resources using either location or name||The main purpose is to get the address or location of a resource|
|Example – contact: +1 883-345-1111,
|Example – https://hackr.io/blog|
|Used in HTML, XML and tag library files like XSLT and jstl to identify resources and binaries.||URL is used to find only web pages|
Java API differences
There are some differences in the way we instantiate URI and URL objects in Java. URI has a specific constructor to give out all parts of the syntax separately, whereas the URL doesn’t have. URL has methods to open a remote connection to obtain the contents of the pointed resource.
While the term URL is more common and we use it every day, one can use URI in general contexts as it is a broader term. URL and URN both are specific and limited. The difference between URI and URL is very subtle and only occurs when URI specifies only the name. When it comes to location, URI is the same as the URL.
People are also reading:
- What is Procedural Programming?
- What is Functional Programming?
- Top Programming Terms for beginners
- How to Learn Programming?
- Which Programming Languages is best for getting Jobs?
- Difference between Structure vs Union
- CSS Cheat Sheet
- PHP Cheat Sheet
- SQL Cheat Sheet