DEV Community

Mystica
Mystica

Posted on • Originally published at mystica.me on

URL vs URN vs URI

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
Enter fullscreen mode Exit fullscreen mode

✨ What is Resource?

A resource can be HTML file, images, API endpoints, services, or any documents, books, research papers, etc.

venn diagram describing how URL and URN are subsets of URI

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
Enter fullscreen mode Exit fullscreen mode

Example of the URL

http:/abc.com/index.html?name=hello#section2 where http:/ is protocol, abc.com is authority, /index.html is location or path, ?name=hello is query, #section2 is fragment

✨ 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)
Enter fullscreen mode Exit fullscreen mode

Examples of URN:

URN:ISBN:9780545162074 where NID is ISBN and NSS is 9780545162074

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
Enter fullscreen mode Exit fullscreen mode

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!
Enter fullscreen mode Exit fullscreen mode

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,

from the above example, http and urn are scheme whereas heir-path is what's following the part of the url or urn in the above examples

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>
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

On running above html code, the browser console displaying URN as Failed to launch 'urn:mrn:iala:pub:g1143' because the scheme does not have a registered handle,for mail and ftp, it displays Launched external handler

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. diagram explaining the user clicks on the link that takes them to specific app and then deep linking checks whether the app is installed or not in user device, if yes then open the app and shows content. if not installed, it goes to play store or app store to install the app

  • TLDR;
  • ⭐ URL (location) starts with "protocol:"
  • ⭐ URN (namespace) starts with "urn:"
  • ⭐ URI - both URL and URN can be called as URI.

Top comments (0)