-
Notifications
You must be signed in to change notification settings - Fork 22
URI Template Format
Amiel Martin edited this page Dec 26, 2015
·
9 revisions
Url templates are compiled with geraintluff/uri-templates, which fully implements RFC 6570 level 4.
Url templates use variable expansion using single curly braces (ie {variable}
).
Certain prefixes alter the way variables are expanded.
-
+
- Reserved Expansion -
/
- Path Segments -
?
- Query Expansion -
&
- Query Continuation -
#
- Fragment Expansion -
.
- Label Expansion -
;
- Path-style Parameters
-
:
- The Prefix Modifier limits the number of characters expanded, like truncate. -
*
- The Explode Modifier indicates that each member in a collection is to be expanded as a separate value.
The following examples use the following inputs to demonstrate how different inputs are expanded.
{
"undef": undefined,
"id": 123,
"key": "abcdef",
"string": "Hello World!",
"path": "/foo/bar",
"host": "http://example.com",
"list": ["red", "green", "blue"],
"list[]": ["magenta", "cyan", "yellow"],
"object": { "category": "featured", "enabled": true },
}
Expression | Expansion |
---|---|
{string} |
Hello%20World%21 |
{string:6} |
Hello%20 |
/photos/{id} |
/photos/123 |
{path} |
%2Ffoo%2Fbar |
{host} |
http%3A%2F%2Fexample.com |
{list} |
red,green,blue |
{object} |
category,featured,enabled,true |
{object*} |
category=featured,enabled=true |
Expression | Expansion |
---|---|
{+string} |
Hello World! |
{+path} |
/foo/bar |
{+host} |
http://example.com |
Expression | Expansion |
---|---|
{/string} |
/Hello%20World%21 |
{/undef} |
(empty string) |
{/list} |
/red,green,blue |
{/list*} |
/red/green/blue |
{/key,id} |
/abcdef/123 |
Expression | Expansion |
---|---|
{?undef} |
(empty string) |
{?key,id} |
?key=abcdef&id=123 |
{?list} |
?red,green,blue |
{?list*} |
?v=red&v=green&v=blue |
{?list[]*} |
?list[]=magenta&list[]=cyan&list[]=yellow |
{?object} |
?category,featured,enabled,true |
{?object*} |
?category=featured&enabled=true |
{?object*,key} |
?category=featured&enabled=true&key=abcdef |
Expression | Expansion |
---|---|
{&undef} |
(empty string) |
{&key,id} |
&key=abcdef&id=123 |
{?key}{&id} |
?key=abcdef&id=123 |
{&list*} |
&v=red&v=green&v=blue |
{&list[]*} |
&list[]=magenta&list[]=cyan&list[]=yellow |
{&object*} |
&category=featured&enabled=true |
{&object*,key} |
&category=featured&enabled=true&key=abcdef |
URI Templates are extremely powerful and not fully documented here.
To learn about all of the possibilities, check out the RFC.