url

RFC 3986 and WHATWG-URL-aligned URL parsing, building, and component encoding. Split URLs into named components, reconstruct them, percent-encode and decode arbitrary byte sequences, and parse or serialize query strings. The parse-then-build round-trip is canonical rather than byte-identical: it strips default ports, lowercases scheme and host, and normalizes percent-encoding. Transport is out of scope — this module produces URL strings and parsed components, not network requests.

url:parse

[$url:parse] -> element — Parse a URL string into its components, strict per RFC 3986 generic syntax.

            [?lib 'cx-stdlib/url']
[$url:parse "https://example.com/path?q=1"]
          
            [url [scheme 'https'] [host 'example.com'] [path '/path'] [query 'q=1']]
          

url:parse-lenient

[$url:parse-lenient] -> element — Parse a URL with best-effort recovery for messy real-world input.

            [?lib 'cx-stdlib/url']
[$url:build [$url:parse-lenient "https://example.com\\path"]]
          
            'https://example.com/path'
          

url:parse-whatwg

[$url:parse-whatwg] -> element — Parse a URL using the WHATWG model for browser-exact web-URL behavior.

            [?lib 'cx-stdlib/url']
[$url:build [$url:parse-whatwg "https://example.com\\path"]]
          
            'https://example.com/path'
          

url:parse-with-opts

[$url:parse-with-opts] -> element — Parse a URL with explicit options for parsing model and default scheme.

            [?lib 'cx-stdlib/url']
[$url:build [$url:parse-with-opts "example.com/path" {"default-scheme": "https"}]]
          
            'https://example.com/path'
          

url:build

[$url:build] -> string — Assemble a URL string from components, auto-encoding raw values and canonicalizing.

            [?lib 'cx-stdlib/url']
[$url:build [$url:parse-lenient "https://example.com\\path"]]
          
            'https://example.com/path'
          

url:build-raw

[$url:build-raw] -> string — Assemble a URL string from pre-encoded components without re-encoding their content.

            [?lib 'cx-stdlib/url']
[$url:build-raw [url [scheme "https"] [host "api.example.com"] [path "/users/a%2Fb%20c/profile"]]]
          
            'https://api.example.com/users/a%2Fb%20c/profile'
          

url:normalize

[$url:normalize] -> string — Return the canonical form of a URL string — equivalent to parse then build.

            [?lib 'cx-stdlib/url']
[$url:normalize "HTTPS://EXAMPLE.com:443/%2f"]
          
            'https://example.com/%2F'
          

url:encode

[$url:encode] -> string — Percent-encode a string with the generic set, leaving unreserved characters alone.

            [?lib 'cx-stdlib/url']
[$url:encode "a b/c"]
          
            'a%20b%2Fc'
          

url:decode

[$url:decode] -> string — Percent-decode a string and return UTF-8, raising on malformed sequences.

            [?lib 'cx-stdlib/url']
[$url:decode "a%20b%2Fc"]
          
            'a b/c'
          

url:query-parse

[$url:query-parse] -> map — Parse a query string into a map, with repeated keys collected into a sequence.

            [?lib 'cx-stdlib/url']
[$url:query-parse "a=1&b=2&a=3"]
          
            {a: ('1', '3'), b: '2'}
          

url:query-encode

[$url:query-encode] -> string — Serialize a map into a query string, with sequence values producing repeated keys.

            [?lib 'cx-stdlib/url']
[$url:query-encode [$url:query-parse "a=1&b=2&a=3"]]
          
            'a=1&a=3&b=2'
          

url:join

[$url:join] -> string — Resolve a reference relative to a base URL per RFC 3986.

            [?lib 'cx-stdlib/url']
[$url:join "http://a/b/c/d;p?q" "g"]
          
            'http://a/b/c/g'
          

url:is-absolute

[$url:is-absolute] -> bool — Report whether a URL is absolute — true iff it has a scheme component.

            [?lib 'cx-stdlib/url']
[$url:is-absolute "https://example.com/x"]
          
            true