NAME
std/net/url - URL parsing, escaping, and templates.
SYNOPSIS
from std/net/url import *;
let parsed := parse(
"https://api.example.com/v1?q=tea%20time"
);
let encoded := escape("tea time");
let text := unescape(encoded);
let url := fill_template(
"https://api.example.com/{version}/items/{id}{?q}",
{ version: "v1", id: 7, q: "tea time" }
);
IMPLEMENTATION SUPPORT
This module is supported by all implementations of ZuzuScript.
DESCRIPTION
This module provides small URL helpers.
EXPORTS
Functions
escape(value)Parameters:
valueis any value. Returns:String. Percent-encodesvaluefor use in URLs.unescape(value)Parameters:
valueis URL-escaped text. Returns:String. Decodes percent-escaped text.parse(url)Parameters:
urlis a URL string. Returns:Dict. Parsesurland returns a dictionary with:url,scheme,authority,userinfo,host,port,path,query,fragment, andquery_params.fill_template(template, values)Parameters:
templateis an RFC 6570 URI Template andvaluesis a dictionary or pair list of template variables. Returns:String. Expands the template usingvalues.This is a complete implementation of RFC 6570 (all four levels), validated against the official URI Template test suite. All expression operators are supported:
{var}- simple string expansion;{+var}- reserved expansion, leaving URI-reserved charactersand percent-encoded triplets intact;
{#var}- fragment expansion;{.var}- label expansion with a dot prefix;{/var}- path segment expansion;{;var}- path-style parameter expansion;{?var}- form-style query expansion;{&var}- form-style query continuation.
Each variable in an expression may take the
:Nprefix modifier (expand only the first N characters of a string value, with N between 1 and 9999) or the*explode modifier (expand list and dictionary members as separate items), and expressions may name several variables separated by commas, for example{?q,page,lang}.Variable values may be Strings (or Numbers and Booleans, which are rendered as text), Arrays (RFC 6570 list values), or Dicts and pair lists (RFC 6570 associative values; dictionary keys are expanded in sorted order). Variables that are null, missing, or empty lists or dictionaries are undefined per RFC 6570 and are omitted from the expansion.
Invalid templates - unbalanced braces, unknown operators, malformed variable names or modifiers, or a
:Nprefix applied to a list or dictionary value - throw an exception.
COPYRIGHT AND LICENCE
std/net/url is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.