codec/url
lib/codec/url.vklib/codec/url.vk Pure-Veko RFC 3986 URL parser, formatter, percent-encoding, and query string codec. Zero capabilities required.
Url = struct { scheme str = ..., userinfo str = ..., host str = ..., port i64 = ..., path str = ..., query str = ..., fragment str = ... }
Structured representation of a parsed RFC 3986 URL.
encode-component = fn [s str] str
Percent-encodes a URL component per RFC 3986 (spaces become %20).
Executable Example
use [url = codec/url]
e = url/encode-component 'hello world/v1'
if e != 'hello%20world%2Fv1' or (url/decode-component e) != 'hello world/v1' [ err 'url enc' ] else [ .ok ]
decode-component = fn [s str] str
Decodes a percent-encoded URL component (also converting + when plus_as_space is false -> leaves + literal).
parse = fn [raw_url str] Url
Parses an RFC 3986 URL string into a Url struct.
Executable Example
use [url = codec/url]
u = url/parse 'https://api.veko.dev:8443/v1/nodes?region=eu#top'
if u.scheme != 'https' or u.host != 'api.veko.dev' or u.port != 8443 or u.path != '/v1/nodes' or u.query != 'region=eu' or u.fragment != 'top' [
err 'url/parse'
] else [ .ok ]
parse-query = fn [q str] map[str]
Parses a URL query string ('a=1&b=hello%20world') into a map[str].
Executable Example
use [url = codec/url]
q = url/parse-query 'region=eu-west&limit=25'
if (map/get q 'region') != 'eu-west' or (map/get q 'limit') != '25' [ err 'parse-query' ] else [ .ok ]
encode-query = fn [params map[str]] str
Encodes a map[str] into a percent-encoded query string.