6.9 URI template syntax
Routers in Restlet and Kauri match URIs based on URI templates.
A URI template is basically a string containing named wildcards, called variables, between { and }. An example:
/users/{id}
By default, the variable {id} will only match URI segments, basically any text not containing the slash character.
You can define various options for the variables. The options are specified by adding them comma-separated after the variable name: {var,option1,option2,option3}.
The options are (in sequence of usefulness):
- the type of variable: what characters are consumed by the variable. The default is "uri_segment". See table below.
- should the variable be decoded? By default it is not decoded. Specify option "decode" to decode it.
- is the variable required or not. If not, an empty string will be matched. By default it is required. Specify option "optional" to make the variable optional.
- is the variable fixed. A fixed variable is not really a variable, it will always match the same value, but will still cause a request attribute to be set. Useful for things that might eventually become variable. Specify option "fixed" to make the variable fixed. The fixed value can be specified after the variable name like this: {varname=value,fixed}.
The options can be specified in any order. It does not make sense to specify multiple variable type options.
For example, to decode a variable and match all URI path characters (thus possibly multiple path segments), use:
/users/{id,uri_path,decode}
|
Variable types |
|
|---|---|
|
Option name |
Description |
|
all |
Matches all characters. |
|
alpha |
Matches all alphabetical characters. |
|
alpha_digit |
Matches all alphabetical and digital characters. |
|
comment |
Matches any TEXT excluding "(" and ")". |
|
comment_attribute |
Matches any TEXT inside a comment excluding ";". |
|
digit |
Matches all digital characters. |
|
token |
Matches any CHAR except CTLs or separators. |
|
uri_all |
Matches all URI characters. |
|
uri_fragment |
Matches URI fragment characters. |
|
uri_path |
Matches URI path characters (not the query or the fragment parts). |
|
uri_query |
Matches URI query characters. |
|
uri_scheme |
Matches URI scheme characters. |
|
uri_segment |
Matches URI segment characters. |
|
uri_unreserved |
Matches unreserved URI characters. |
|
word |
Matches all alphabetical and digital characters plus the underscore. |
Previous