URI Templates
Expand RFC 6570 URI Templates — the {var} syntax that OpenAPI links, HAL _links, and hypermedia API clients use to turn a template plus a set of variables into a concrete URI. The full Level 4 grammar is supported: every operator ({+var} reserved, {#var} fragment, {.var} label, {/var} path, {;var} path-style parameters, {?var} query, {&var} query continuation), the {var:3} prefix modifier, and the {var*} explode modifier for lists and associative arrays.
expand(template, vars) returns the expanded string; compile(template) parses once and returns a reusable { expand } for templates applied to many variable sets. A malformed template (an unclosed expression, an unknown operator, or a non-numeric prefix) throws UriTemplateError.
b.uriTemplate.compile(template) #
Parse an RFC 6570 URI Template once and return a reusable { expand(vars) }, so a template applied to many variable sets is parsed a single time. Throws UriTemplateError if the template is malformed.
var t = b.uriTemplate.compile("/users/{id}{?fields*}");
t.expand({ id: 7, fields: ["name", "email"] });
// → "/users/7?fields=name&fields=email"
b.uriTemplate.expand(template, vars) #
Expand an RFC 6570 URI Template against a set of variables and return the resulting URI string. Variable values may be strings, numbers, booleans, arrays (lists), or plain objects (associative arrays); an undefined, null, or empty list/map variable is omitted. Reserved-set encoding, :N prefixes, and * explosion follow RFC 6570 §3.2. Throws UriTemplateError on a malformed template.
b.uriTemplate.expand("{/path}/here{?q,limit}",
{ path: "search", q: "json schema", limit: 10 });
// → "/search/here?q=json%20schema&limit=10"
Last updated 2026-08-08T16:39:49.652Z by seeder.