Skip to content

URITemplate

[Source]

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"
class val URITemplate

Constructors

create

[Source]

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.

new val create(
  template: String val)
: URITemplate val^ ?

Parameters

Returns


Public Functions

expand

[Source]

Expand the template with the given variables.

Always succeeds. Undefined variables produce no output per RFC 6570.

fun box expand(
  vars: URITemplateVariables box)
: String iso^

Parameters

Returns


string

[Source]

Return the original template string.

fun box string()
: String iso^

Returns