url module
Parse and build URLs, encode/decode percent-escapes, and serialize query parameters.
import "url" as url;
var u = url.parse("https://example.com:8080/path?q=hello+world&n=42");
print(u.scheme, u.host, u.port, u.path, u.query.q);
// https example.com 8080 /path hello world
print(url.encode("hello world")); // hello%20world
print(url.build_query({ q: "hi", n: 1 })); // q=hi&n=1
API
| Function | Description |
|---|---|
url.parse(s) → map | {scheme, user, password, host, port, path, query, fragment, raw}. query is a map. |
url.encode(s) → string | Percent-encode a single component. |
url.decode(s) → string | Reverse of encode. |
url.build_query(params) → string | Serialize a {key: value} map into k1=v1&k2=v2. |
url.parse_query(s) → map | Parse k1=v1&k2=v2 (with or without leading ?) into a map. |