Examples Of URI

Shivam
5 min readJan 23, 2020

--

In this Part-III from the series of posts on the URI, I am going to illustrate a few examples of the URI schemes and URN namespaces that we mostly use. If you haven’t read the Part-I and Part-II of this series, then read those posts first. Let’s start with URI schemes.

# URI Scheme Examples:

The following examples illustrate some URI schemes that are mostly used, and You can find a list of all available URI schemes here.

# File

A file URI identifies a file stored on a host machine. The syntax of file URI is as following:

file-URI = file://{authority}/local-path

We have already discussed the authority component in the previous part. The host in the authority component is the fully qualified domain name of the system on which the file is accessible. It can be a localhost or IP address or registered domain name.

For a example to access a local file named `100–2.gif` on my local machine, I can type the following URI in the browser to access it:

file:///Users/shivam/Downloads/gifs/100–2.gif

  • Note- I have not specified any host here, so by default, it will be localhost. We can achieve the same thing with the host as follows:

file://localhost/Users/shivam/Downloads/gifs/100–2.gif

file://127.0.0.1/Users/shivam/Downloads/gifs/100–2.gif

  • Here, the 27.0.0.1 is an internal IP address of my machine.
  • On Windows- or DOS-like file systems, an absolute file path can begin
    with a drive letter. To facilitate this, the “local-path” rule can be replaced with the following:

local-path = [ drive-letter ] path-absolute

  • For example — file:c:/path/to/file

# MAILTO

The ‘mailto’ URI scheme is used to identify resources that are reached using Internet mail. It can contain information like email address, subject, cc, message body, etc.

  • For example, type below URI in a web browser:

mailto:addr1@an.example,addr2@an.example

The above URI will open the default email application with the prefilled recipient information.

  • We can also add more information like a subject, cc, body, etc. For example, type below URI in a web browser:

mailto:infobot@example.com?cc=bob@example.com&subject=current-issue&body=hello

The above URI will open the default email application with the prefilled details of the recipient, subject, cc information, and a message body.

There are many types of URI schemes available in the market today, and If we go into the details of each, it will increase the scope of this blog. So to keep this blog short and simple, in the next section, I have just given the use of the schemes and one example. I have also provided a link to web resources where you can get more information about that particular URI Scheme.

# FTP

  • The FTP URI scheme for File Transfer Protocol services.
  • We can enable file sharing (computer programs and/or data) using FTP with a remote computer.
  • For example, “ftp://ftp.is.co.za/rfc/rfc1808.txt”.
  • You can use FTP from the command line on the Unix based OS. If you get an error: ftp command not found, then you need to install a tool that will enable FTP on your machine. On Mac, you will need the inetutils, and You can install it via homebrew using command brew install inetutils.

# NEWS

  • The ‘news’ URI scheme identifies articles by their worldwide unique
    “Message-ID”, independent of the server and the newsgroup.

newsURI = "news:" [ server "/" ] ( article / newsgroups )

# TELNET

  • The TELNET URI scheme for interactive services via the TELNET Protocol.

telnetURI = telnet://<user>:<password>@<host>:<port>/

  • For example, “telnet://melvyl.ucop.edu/”.

# URN Namespace Examples:

The following examples illustrate some URN namespaces that are mostly used, and you can find a list of all available namespaces here.

# ISBN

The International Standard Book Number (ISBN) is a numeric commercial book identifier that is intended to be unique.

An ISBN is a ten-digit number, which is divided into four variable-length parts, usually separated by hyphens when printed. These parts are listed in the order as follows:

  1. A group identifier which specifies a group of publishers, based on
    national, geographic or some other criteria.
  2. The publisher identifier.
  3. The title identifier.
  4. And a modulus 11 check digit.

For example:

URN:ISBN:0–395–36341–1

There are plans to extend the ISBN into 13 digits in order to make
the system more suitable for identification of electronic monographs.

# UUID

  • The UUID (Universally Unique Identifier) is also unkown as GUID (Globally Unique Identifier).
  • A UUID is 128 bits long, and requires no central registration process. As a result, we can generate them on demand and this process can be automated.
  • The UUID can be used for a multiple of purposes, from tagging objects with a short lifetime, to identifying persistent objects across a network.
  • UUID is a specific sequence of bits in memory, but as we have seen in the Part-I, URI is the sequence of characters. To accurately represent a UUID as a URN, it is necessary to convert the bit sequence to a string representation. This converted value is in the hexadecimal digit string format.
  • The general syntax of the UUID is as follows:

UUID = time_low “-” time_mid “-” time_high_and_version “-”
clock_seq_and_reserved + clock_seq_low “-” node

here:

time_low = 32 bit unsigned integer. The low field of the timestamp.time_mid = 16 bit unsigned integer. The middle field of the timestamp.time_high_and_version = 16 bit unsigned integer. The high field of the timestamp multiplexed with the version number.clock_seq_and_reserved = 8 bit unsigned integer. The high field of the clock sequence multiplexed with the variant.clock_seq_low = 8 bit unsigned integer. The low field of the clock sequence.node = 48 bit unsigned integer. The spatially unique node identifier.
  • UUID The following is an example of the string representation of a UUID as a URN:

urn:uuid:f81d4fae-7dec-11d0-a765–00a0c91e6bf6

  • There are three primary variants of the algorithms for creating the UUID, Time-Based, Name-Based, and using Pseudo-Random Numbers. Going into the detail of each algorithm is not the scope of this blog. You can find more information about them here.

Thanks. That’s all in this part-III. I hope you learned something from this post. If you have any suggestions or questions, please add it in the comment below. Thanks again for reading, Happy Learning 👏.

References:

--

--

Shivam

Product Engineer @ Gojek. Likes to write on Productivity, Android App Development, Kotlin, Software Engineering, etc.