{temple}

A URI Template processor.

Test Drive

Enter a URI Template and some expansion variables (the web demo requires JSON format) in the fields below then click the Expand button to see the result.

Show URI Template Syntax

URI Template

Expansion Variables

URI Template Syntax

URI Templates may contain one or more expressions, and literal text.

Expressions begin with a left brace {, end with a right brace }, and contain comma-separated variables and an optional operator. Each variable can have an optional modifier.

For example, when expanding the template {name} with {name: "Bob"} the expanded text is simply Bob.

There's actually a bit more to it than that, but those are the basics. Read on for more in-depth examples.

Tip: Click the Expand button next to an example to see its expansion in the test drive form.

example.com/~{name}

Operators

Operators determine how variables in the expression will be expanded. Expressions may only have one operator.

Tip: Array and Object values are generally expanded as comma-separated values. The Explode Modifier can change this behavior.

No Operator - Simple String Expansion

When no operator is specified, expanded variables are separated by a comma ,.

{name,age}

{name,beer}

{name,music}

? Form-Style Query Expansion

Expanded variables are named and separated by an ampersand &. The expansion is prefixed by a question-mark ?.

{?name,age}

{?name,beer}

{?name,music}

& Form-Style Query Continuation

Expanded variables are named and separated by an ampersand. The expansion is also prefixed by an ampersand.

{&name,age}

{&name,beer}

{&name,music}

; Path-Style Parameter Expansion

Expanded variables are named and separated by a semi-colon ;. The expansion is also prefixed by a semi-colon.

{;name,age}

{;name,beer}

{;name,music}

/ Path Segment Expansion

Expanded variables are separated by a forward slash /. The expansion is also prefixed by a forward slash.

{/name,age}

{/name,beer}

{/name,music}

/ Fragment Expansion

Expanded variables are separated by a comma. The expansion is prefixed by a fragment delimiter #.

{#name,age}

{#name,beer}

{#name,music}

. Label Expansion

Expanded variables are separated by a dot .. The expansion is also prefixed by a dot.

{.name,age}

{.name,beer}

{.name,music}

+ Reserved Expansion

Reserved characters are those not allowed literally in URIs, or that otherwise have special meaning within URI Templates. By default reserved characters are URL-encoded in the expansion. The + operator disables this behavior.

{reserved}

{+reserved}

Modifiers

Modifiers change how variables appear in the expanded URI.

:<n> Prefix Modifier

Limits the expanded value to the number of characters specified by <n>. Prefix modifiers are ignored for Array and Object values.

{name:1,age:1}

{name:10,beer:3}

{?name:1,music:3}

* Explode Modifier

Explodes an Array or Object value into name-value pairs. Arrays are exploded for operators that would normally expand named variables (such as the Query Expansion modifier ?). Objects are exploded regardless of operator type.

{name,age,beer}

{name,age,beer*}

{?name,age,beer*}

{name,age,music}

{name,age,music*}

{/name,age,music*}

Fork me on GitHub