Inherited from v1.0.0

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

FunctionDescription
url.parse(s) → map{scheme, user, password, host, port, path, query, fragment, raw}. query is a map.
url.encode(s) → stringPercent-encode a single component.
url.decode(s) → stringReverse of encode.
url.build_query(params) → stringSerialize a {key: value} map into k1=v1&k2=v2.
url.parse_query(s) → mapParse k1=v1&k2=v2 (with or without leading ?) into a map.

See also

  • webreq.query / req.params for incoming HTTP requests.
  • request — pass query opts to URL-encode automatically.