Definition
Uniform Resource Identifier (URI): Generic Syntax. Defines the syntax and semantics of URIs including schemes, authorities, paths, queries, and fragments. Foundation for all web addressing.
Example
RFC 3986 defines that https://api.example.com:443/users?role=admin#top breaks down into scheme (https), authority (api.example.com:443), path (/users), query (?role=admin), and fragment (#top).
Analogy
Like the postal service rules that define how addresses must be formatted - everyone follows the same structure so mail (or web requests) reaches the right destination.
Code Example
// URI components per RFC 3986
foo://example.com:8042/over/there?name=ferret#nose
_/ ______________/_________/ _________/ __/
| | | | |
scheme authority path query fragment
// Percent-encoding (URL encoding)
const encoded = encodeURIComponent('hello world!');
// Result: 'hello%20world%21'
// Reserved characters: : / ? # [ ] @ ! $ & ' ( ) * + , ; =
const unsafe = '[email protected]';
const safe = encodeURIComponent(unsafe);
// Result: 'user%40example.com'
// Building URIs
const baseUri = 'https://api.example.com';
const path = '/users';
const query = '?role=admin&active=true';
const fullUri = baseUri + path + query;
// Result: https://api.example.com/users?role=admin&active=true
Standards & RFCs
Standards & RFCs