Wednesday, July 25, 2018

The Difference Between URI, URL and URN

This small post briefly explains the difference between URI, URL and URN. Sometimes the first two terms are used interchangeably, and the last one is encountered less frequently in software development. Anyway, it is a good idea to understand the difference between them.

URI (Uniform Resource Identifier)

In accordance with Wikipedia, a Uniform Resource Identifier (URI) is a string of characters designed for unambiguous identification of resources and extensibility via the URI scheme. In other words, URI is designed to uniquely identify a resource, but it may lack of information about the location or retrieval protocol of a resource. URI is defined by schemes. Schemes specify concrete syntax and associated protocols. The most known URI type is Uniform Resource Locator (URL). More information about URI can be found here.

There are a few URI examples:
  • http://www.example.com/index.html — URI which is also a URL.
  • data:,Example%20URI — URI which is not a URL (this is a data URI).
  • view-source:http://www.example.com/index.html — another example of URI which is not a URL (this is a URC).

URL (Uniform Resource Locator)

Wikipedia says that a Uniform Resource Locator (web address) is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. In other words, URL contains two additional pieces of information that may be missing from URI (depending on URI scheme): a location and a retrieval protocol for a resource. This is the key difference between URL and URI. Another important thing to remember: every URL is a URI, but not vice versa. More information about URL can be found here.

There are a few URL examples:
  • mailto:admin@example.com
  • http://www.example.com/index.html
  • /other/link.html — relative URL

URN (Uniform Resource Name)

A Uniform Resource Name is yet another form of URI. It uses 'urn' scheme to identify a resource with a unique and persistent name. More information about URN can be found here.

There are a few URN examples:
  • urn:uuid:1be065ad-43e0-4d34-bd66-6ffc005f2edf — globally unique identifier (GUID).
  • urn:isbn:1231231234 — identifies a book by ISBN.

That's it.
Thanks for reading!