Router
The router
section is optional. Many applications will not need one. However, it can be used to assign names to RESTful parameters (which otherwise would only be available via position index).
The router
element contains zero or more route
entries. Each route
entry has the following attributes.
Attribute | Default | Notes |
---|---|---|
path |
(none) | This is the path pattern to match. It begins with a leading / . The route path is compared against the supplied inbound request path. The app-name and any script location is removed from the inbound request path before matching is applied.Each component in the path must be one of: • An empty part (matches any inbound part). • An Asterix * (matches any inbound party).• An exact string to match. • A colon-prefixed :<var> variable to extract. |
dataset |
(none) | Specify the name of the dataset to be executed if this path pattern is matched. This may be a standard XML-file defined dataset within dataset_dir , or it may be the name of a virtual dataset implemented by a plugin or exec definition. |
presentation |
array |
Specifies if the returned data will be given back as an array (the default), or as an singleton . If singleton is specified then:• The query must return exactly 1 object. • The object is returned as top level data, with no wrapper. • Jarvis will return 404 if the query returns no rows. • Jarvis will die if the query returns > 1 row.Singleton formatting applies only to json and json.rest return formats. Specifying singleton will not affect the return encoding for other formats, although the row count validation will still be performed. |
For example, consider the configuration:
<router>
<route path="/boat_class/:boat_class" dataset="boat_class"/>
<route path="/*/by-class/:boat_class" dataset="boat"/>
<route path="/boat/:id" dataset="boat" presentation="singleton"/>
</router>
Now consider the following request:
http://localhost/jarvis-agent/demo/boat/by-class/X%20Class
The processing is as follows:
Comparison Against Route 1
- The leading script location
http://localhost/jarvis-agent
is removed. - The application name
/demo
is removed. - The supplied path
boat/by-class/X%20Class
is matched against the routes in order.
The first route compares supplied boat
against an exact string boat_class
and the match fails.
Comparison Against Route 2
- Part one compares
boat
against the wildcard*
and passes. - Part two compares
by-class
against exactby-class
and passes. - Part three assigns
X Class
to the variableboat_class
. - The dataset
boat
is selected.
Outcome
The final resulting route match is:
- The dataset is
boat
. - The parameter
{$1}
in a dataset XML will expand toboat
. - The parameter
{$2}
in a dataset XML will expand toby-class
. - The parameter
{$3}
in a dataset XML will expand toX Class
. - The parameter
{$boat_class}
in a dataset XML will expand toX Class
.
Note: When performing insert/update/delete
requests, any per-row value for {$boat_class}
will override the URL-supplied value for {$boat_class}
.