Skip to content

URITemplateBuilder

[Source]

A convenience builder for one-shot URI template expansion.

Combines template parsing, variable binding, and expansion into a single fluent chain. Use this when you need to expand a template once and don't need to reuse the parsed template or inspect parse errors.

For repeated expansion of the same template, parse once with URITemplate and call expand() multiple times. For detailed parse error reporting, use URITemplateParse.

let uri = URITemplateBuilder("{scheme}://{host}{/path*}")
  .set("scheme", "https")
  .set("host", "example.com")
  .set_list("path", ["api"; "v1"; "users"])
  .build()?
// => "https://example.com/api/v1/users"
class ref URITemplateBuilder

Constructors

create

[Source]

Create a builder for the given URI template string.

The template is not parsed until build() is called, so construction always succeeds.

new ref create(
  template: String val)
: URITemplateBuilder ref^

Parameters

Returns


Public Functions

set

[Source]

Bind a string variable. Returns this builder for chaining.

fun ref set(
  name: String val,
  value: String val)
: URITemplateBuilder ref

Parameters

Returns


set_list

[Source]

Bind a list variable. Returns this builder for chaining.

fun ref set_list(
  name: String val,
  values: Array[String val] val)
: URITemplateBuilder ref

Parameters

Returns


set_pairs

[Source]

Bind an associative array variable. Returns this builder for chaining.

fun ref set_pairs(
  name: String val,
  pairs: Array[(String val , String val)] val)
: URITemplateBuilder ref

Parameters

Returns


build

[Source]

Parse the template and expand it with the bound variables.

Raises an error if the template has invalid syntax. Use URITemplateParse instead when you need a description of what went wrong.

fun box build()
: String iso^ ?

Returns