URL vs URN vs URI
🕔 Wed Jun 22 2022
Before going into the understanding of these three acronyms, we will learn what is the resource in the acronym of the URL, URN, URI .
URN - Uniform Resource Namespace
URL - Uniform Resource Locator
URI - Uniform Resource Identifier
✨ What is Resource?
A resource can be HTML file, images, API endpoints, services, or any documents, books, research papers, etc.
From the above diagram, we can able to see that URL and URN are the Subsets of URI (Uniform Resource Identifier). We will see what is URL and URN followed by URI.
✨ URL
It is used to locate Specific resources on the web server or other. It knows where to find them.
Syntax of URL as follows:
URL = Scheme/Protocol ":" Scheme_Specific_Path
where,
Scheme/Protocol = http,ftp,etc
Scheme_Specific_Path = path/to/retreival/of/resource
Example of the URL
✨ URN
- it is the persistent labeling of the resources with an identifier. It does not imply where to find the resource. It is a globally unique name for the resources.
Syntax of URN According to RFC2141:
URN = "urn:" <NID> ":" <NSS>
where,
<NID> = NameSpace Identifier (case-insensitive, globally unique)
<NIS> = NameSpace Specific String (can contain query/fragments)
Examples of URN:
Here in the example, we can able to see ISBN is unique for the books and it just tells what is the ISBN id for the book rather than where to find them...
And from the above example, If we change the NID to
urn:isbn:9780545162074
urn:Isbn:9780545162074
urn:ISBN:9780545162074
urn:IsBn:9780545162074
The above all are the same since it is case-sensitive
Check out other examples in wiki
✨ URI
What is the common between these terms??
URN and URL follow the URI Syntax and it's the subset of URI.
Syntax of URI According to RFC3986:
URI = Scheme : heir-part [? query] [# fragment]
where
- heir-part = authority or path (example.com / isbn:9780747532743)
- [? query] and [# fragment] are optional ones!
From the above syntax, we can able to see the "Scheme" in the syntax matches with "scheme/protocol" in URL Syntax or "urn" in the URN Syntax.
Combining both of the above examples from URL and URN,
we can able to distinguish that both URN and URL follow the URI Syntax.
Where we are using URI then??
In HTML,
<a href="uri scheme">SCHEME</a>
the value of href can be http, ftp,mailto, urn, and other URI Schemes. It can be found on MDN href supports URI Schemes which means we can do ("urn:isbn:0747532745"). And one of the common URI schemes we use "mailto:"... web browsers execute something called protocol handlers to handle the URI Schemes that are not HTTP/HTTPS.
code:
<a href="urn:mrn:iala:pub:g1143">URN</a>
<a href="mailto:mysticainf@gmail.com">mail</a>
<a href="ftp://speedtest.tele2.net">ftp</a>
In the above example, mailto: is one of the URI Scheme in which "mailto" will be scheme name and email id is the scheme path.
URN failed because the web browser can't able to resolve the URN to URL...
And we do Deep Linking (the link that sends the user directly to the app installed on their phone instead of using the web version of the app on the browser)... we use URI Scheme for the app to enable deep linking. It is one of the use cases for the URI Scheme.
- TLDR;
- ⭐ URL (location) starts with "protocol:"
- ⭐ URN (namespace) starts with "urn:"
- ⭐ URI - both URL and URN can be called as URI.