Uniform Resource Identifier (URI)
A Uniform Resource Identifier (URI) is a sequence of characters that refers to the identity of a resource, thereby allowing resources to be distinguished from one another. Resources can be differentiated based on their location on the internet, their name, or both.
There are two types of URI; the Uniform Resource Locator (URL) and Uniform Resource Name (URN).
URLs and URNs
A URI can distinguish between physical or logical resources that are available on the web. Resources can represent web pages and other electronic resources but also, can be used to identify people, places, objects, and even ideas or concepts.
A URI that also specifies the location of the resource is a Uniform Resource Locator (URL).
A URI that provides only a unique name for a resource, without details about where it can be found, is a Uniform Resource Name (URN).
Usage
The format of the URI syntax is as follows:
scheme : [// authority] path [? query] [# fragment]
Scheme is a required keyword that refers to a scheme that is registered by the Internet Assigned Numbers Authority (IANA). It is case-insensitive, begins with a letter, and is followed by any combination of letters, digits, the plus +
, hyphen -
, or period .
characters. Some commonly used schemes are http, https, and ftp. The complete list of URI schemes is maintained by IANA.
Authority is an optional component that is prefixed by two slashes //
. It contains the userinfo, host, and port components.
Userinfo is an optional component that contains a username and optionally, a password. The syntax username:password
was commonplace before it was deprecated due to security concerns. If the userinfo component exists then it is followed by the at symbol @
to indicate the start of the host.
The host represents either a registered name or an IP address. If the IP address is in the IPv4 format then it must be formatted using dot-decimal notation. IpV6-formatted IP addresses are required to be enclosed in brackets [ ]
.
Port is an optional component that indicates which port the host is available on. It is preceded with a colon :
.
Path is a required component made up of a set of path segments, each delimited by a slash /
. Although the path is required for every URI, it can be zero-length, or empty. If a segment is empty then it will be denoted with two slashes //
, although this is not permitted if the authority is not included in the URI.
Query is an optional component that will be prefixed with a question mark ?
if it is present. The query string is used by the client to specify data or instructions for the server, and will be of a format that is expected and/or specified by the server.
Fragment is an optional component that will be prefixed with a hash #
if it is present.
Examples
Example #1
http://www.example.re/doc/glossary#introduction
Component name | Value |
---|---|
Scheme | http |
Authority | www.example.re |
Path | /doc/glossary |
Fragment | introduction |
Example #2
https://example.re:5001/scripts/?job=111&task=1#main
Component name | Value |
---|---|
Scheme | https |
Authority | example.re |
Port | 5001 |
Path | /scripts/ |
Query | job=111&task=1 |
Fragment | main |
Example #3
tel: +1-212-555-1212
Component name | Value |
---|---|
Scheme | tel |
Path | +1-212-555-1212 |
Example #4
ftp://ftp.example.re/doc/glossary.pdf
Component name | Value |
---|---|
Scheme | ftp |
Authority | ftp.example.re |
Path | /doc/ |
Takeaway
A Uniform Resource Identifier (URI) uniquely identifies a resource by location, name, or both. A URI that specifies a location is a URL, whereas one that distinguishes it by name is called a URN.