URITemplate¶
A parsed URI template (RFC 6570) ready for variable expansion.
Parse a template string into a URITemplate, then call expand() with
variable bindings to produce the expanded URI. Use URITemplateParse for
detailed error information on invalid templates, or the convenience
constructor on this class when error details aren't needed.
let tpl = URITemplate("{scheme}://{host}{/path*}{?query*}")?
let vars = URITemplateVariables
vars.set("scheme", "https")
vars.set("host", "example.com")
vars.set_list("path", ["api"; "v1"; "users"])
vars.set_pairs("query", [("page", "1"); ("limit", "10")])
let uri: String val = tpl.expand(vars)
// uri == "https://example.com/api/v1/users?page=1&limit=10"
Constructors¶
create¶
Parse a URI template string.
Raises an error if the template has invalid syntax. Use URITemplateParse
instead when you need a description of what went wrong.
Parameters¶
- template: String val
Returns¶
- URITemplate val^ ?
Public Functions¶
expand¶
Expand the template with the given variables.
Always succeeds. Undefined variables produce no output per RFC 6570.
Parameters¶
- vars: URITemplateVariables box
Returns¶
- String iso^
string¶
Return the original template string.
Returns¶
- String iso^