kex docs Standard Library

URI

module URI

parse

parse(text: String) -> Result<URI, URIError>

Strictly parses an ASCII RFC 3986 URI reference.

Returns the reference or a precise syntax error

Examples

+URI.parse("../images/logo.svg").try+

fromIRI

fromIRI(text: String) -> Result<URI, URIError>

Converts a Unicode IRI to an ASCII URI using IDNA and UTF-8 percent encoding.

Returns the converted URI or a conversion error

Examples

+URI.fromIRI("https://münich.example/straße").try+

record URI

Strict RFC 3986 URI values, hierarchical URLs, query strings, and HTML form encoding. Parsing preserves caller spelling; normalization is always explicit.

using URI

let base = URL.parse("https://example.test/a/").try
let reference = URI.parse("../items?limit=10").try
base.resolve(reference).try.string

A parsed RFC 3986 URI reference. Construction is strict; use parse rather than building this representation directly. string preserves the spelling supplied by the caller, while normalize is explicit.

Fields

source
String

Implements Showable, Inspectable.

Methods

string

string : String

Returns the caller-supplied URI spelling

normalize

normalize : URI

Returns an explicitly normalized RFC 3986 representation

equivalent?

equivalent?(other: URI) -> Bool

Returns whether normalized representations are equal

resolve

resolve(reference: URI) -> Result<URI, URIError>

Resolves a URI reference against this absolute base.

scheme

scheme : String?

Returns the normalized scheme when present

host

host : Host?

Returns the parsed authority host when present

query

query : Query?

Returns the parsed query when present, including an empty query

showValue Showable

showValue : String

Renders with any authority password replaced by ***.

inspectValue Inspectable

inspectValue(colors: Bool) -> String

Structural inspection is also credential-safe.

From Showable

record URL

An absolute hierarchical URI with an authority component.

Fields

source
String

Implements Showable, Inspectable.

Methods

string

string : String

Returns the caller-supplied URL spelling

normalize

normalize : URL

Returns an explicitly normalized URL

equivalent?

equivalent?(other: URL) -> Bool

Returns whether normalized representations are equal

resolve

resolve(reference: URI) -> Result<URL, URIError>

Resolves a URI reference while preserving the URL invariant.

scheme

scheme : String

Returns the normalized scheme

host

host : Host

Returns the authority host

query

query : Query?

Returns the parsed query when present

showValue Showable

showValue : String

Renders with any authority password replaced by ***.

inspectValue Inspectable

inspectValue(colors: Bool) -> String

Structural inspection is also credential-safe.

From Showable

record Host

A host's display spelling and normalized ASCII/IDNA spelling.

Fields

display
String
ascii
String

record Query

Ordered URI query entries. None distinguishes a bare key from key=.

Fields

entries
[(String, String?)]

Methods

encode

encode : String

Encodes according to generic RFC 3986 query rules.

record Form

Ordered application/x-www-form-urlencoded entries.

Fields

entries
[(String, String?)]

Methods

encode

encode : String

Encodes according to HTML form rules, including space as ++.

record URIError

A typed URI parsing, conversion, or resolution failure.

Fields

message
String
position
Integer?

type URIErrorKind

Stable URI failure categories.

Variants

  • InvalidSyntax
  • InvalidEscape
  • InvalidAuthority
  • InvalidPort
  • NonASCII
  • NotAbsolute
  • NotHierarchical
  • MissingAuthority
  • UnsupportedScheme

module URI.URL

parse

parse(text: String) -> Result<URL, URIError>

Parses an absolute hierarchical URL with an authority.

Examples

+URL.parse("https://example.test/path?q=1").try+

build

build : String -> String -> [String] -> Query -> Result<URL, URIError>

Builds and validates a URL from decoded path segments and a query value.

module URI.Query

from

from(entries: [(String, String?)]) -> Query

Builds a query while preserving order, duplicates, and bare keys.

parse

parse(text: String) -> Result<Query, URIError>

Parses generic URI query encoding; ++ remains a literal plus.

Examples

+Query.parse("tag=kex&tag=beam&flag").try+

module URI.Form

from

from(entries: [(String, String)]) -> Form

Builds a form value while preserving order and duplicates.

parse

parse(text: String) -> Result<Form, URIError>

Parses form encoding where ++ represents a space.

Examples

+Form.parse("query=hello+world").try+