Functions
build
fn (parts: Map): Str
Build a URI string from a map of components.
The query field can be a Str or a Map (which gets form-encoded).
Example
::uri/build({scheme: "https", host: "example.com", path: "/users", query: {active: true}})
// "https://example.com/users?active=true"
decode
fn (value: Str): Str
Percent-decode a URI string.
Example
::uri/decode("hello%20world") // "hello world"
decode-query
fn (query: Str): Map
Decode a query string into a Map. Strips a leading ? if present.
Example
::uri/decode-query("city=Salt+Lake+City&days=3")
// {city: "Salt Lake City", days: "3"}
encode
fn (value: Str): Str
Percent-encode a URI component string (RFC 3986). Encodes everything except unreserved characters: A-Z a-z 0-9 - . _ ~
Example
::uri/encode("hello world") // "hello%20world"
::uri/encode("a=1&b=2") // "a%3D1%26b%3D2"
encode-query
fn (params: Map): Str
Encode a Map into a query string (application/x-www-form-urlencoded).
Spaces are encoded as +.
Example
::uri/encode-query({city: "Salt Lake City", days: 3})
// "city=Salt+Lake+City&days=3"
is-valid
fn (uri: Str): Bool
Check if a string is a valid URI.
Example
::uri/is-valid("https://example.com") // true
::uri/is-valid("://broken") // false
join
fn (base: Str, part1: Str): Str
fn (base: Str, part1: Str, part2: Str): Str
fn (base: Str, part1: Str, part2: Str, part3: Str): Str
Join URI path segments against a base URI. Also supports RFC 3986 relative reference resolution.
Example
::uri/join("https://api.example.com", "users", "123")
// "https://api.example.com/users/123"
::uri/join("https://example.com/a/b", "../c")
// "https://example.com/c"
parse
fn (uri: Str): Uri
Parse a URI string into a Uri typed map.
Example
uri ::uri/parse("https://user:pass@example.com:8080/path?q=1#frag")
uri.scheme // "https"
uri.host // "example.com"
uri.port // 8080
Types
Uri
fn (s: Str): Uri
Uri type {
scheme: Str,
userinfo: Str?,
host: Str?,
port: Int?,
path: Str,
query: Str?,
fragment: Str?
}
A parsed URI with structured access to its components.
Fields
scheme- URI scheme (e.g. "https", "mailto")userinfo- User info before @ (nullable)host- Hostname (nullable, absent for non-hierarchical URIs)port- Port number (nullable)path- URI pathquery- Query string without leading ? (nullable)fragment- Fragment without leading # (nullable)
Examples
uri Uri("https://example.com:8080/path?q=1#top")
uri.scheme // "https"
uri.host // "example.com"
uri.port // 8080
uri.path // "/path"
uri.query // "q=1"
// Uri auto-coerces to Str
::http/get(uri) // works — Uri -> Str coercion
Str(uri) // "https://example.com:8080/path?q=1#top"