Uniform Resource Identifier (URI)#
A Uniform Resource Identifier (URI) is a string of characters used to identify a resource. Web-URLs, for example, are a common type of URIs.
Syntax#
scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
- scheme:
http
,ftp
,file
,coap
, etc. - query: a sequence of key-value pairs. E.g.
key1=value1&key2=value2
Example
user host port
┌┴─┐ ┌───┴───┐ ┌┴┐
https://john@github.com:123/repo/master/?color=true&mode=raw#L123
└─┬─┘ └───────┬───────────┘└───┬───────┘└──────────┬───────┘└─┬─┘
scheme authority path query fragment
URI Parser#
-
scheme:
-
authority:
(user:
-
path:
-
query:
-
fragment:
Escape Characters#
⇦ enc/dec ⇨
The characters allowed in a URI are either reserved, unreserved or
percent-encoded (e.g. %3F
for a ?
).
- reserved characters:
: / ? # [ ] @ ! $ & ' ( ) * + , ; =
- unreserved characters:
a-z
,A-Z
,0-9
,- _ . ~
- percent-encodings:
Char | Escape | Char | Escape | Char | Escape |
---|---|---|---|---|---|
space | %20 |
, |
%2C |
^ |
%5E |
! |
%21 |
/ |
%2F |
_ |
%5F |
" |
%22 |
: |
%3A |
{ |
%7B |
# |
%23 |
; |
%3B |
| |
%7C |
$ |
%24 |
< |
%3C |
} |
%7D |
% |
%25 |
= |
%3D |
~ |
%7E |
& |
%26 |
> |
%3E |
||
' |
%27 |
? |
%3F |
ä |
%C3%A4 |
( |
%28 |
@ |
%40 |
ö |
%C3%B6 |
) |
%29 |
[ |
%5B |
ü |
%C3%BC |
* |
%2A |
\ |
%5C |
÷ |
%C3%B7 |
+ |
%2B |
] |
%5D |
ø |
%C3%B8 |
Relationship to URN and URL#
URN and URL are types of URIs. A Uniform Resource Name (URN) can be compared to a person's name, while a Uniform Resource Locator (URL) can be compared to their street address. In other words, a URN identifies an item and a URL provides a method for finding it.
Example URNs:
urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66
urn:isbn:0451450523