The routes (<routes>) is prioritized by the order in the routing list.
There are 3 types of routes being supported.
Directive | Description |
---|---|
controller | A routing directive for dynamic content handled by a controller. |
resource | A routing directive for static content/resource. |
redirection | A routing directive for relaying requests with redirection. |
Attribute | Description | Expected Values |
---|---|---|
pattern | the routing pattern | regular expression or simple pattern (string) |
regexp | the flag to indicate whether the given routing pattern is simplified | true or false (boolean) |
In general, the attribute pattern of any routing directives is to indicate the routing pattern where the directive intercepts, process and respond to any requests to the pattern. Each routing pattern is unique from each other.
New in version 2.1.
By default, similar to Tornado, Tori Framework uses the normal regular expression for routing. However, this could introduce an error-prone routing table for anyone that does not know the regular expression. Here is the syntax where the routing resolver considers in the following presented order.
Simple Pattern Syntax | Equvalent Regular Expression |
---|---|
** | (.+) |
* | ([^/]+) |
{name} | (?P<name>.+) |
Here are the simple versions of routing patterns.
Simple Pattern | Equivalent Regular Expression | Expected Parameter List/Map |
---|---|---|
/abc/def/ghi/** | /abc/def/ghi/(.+) | index 0 or the first key |
/abc/def/ghi/*/jkl | /abc/def/ghi/([^/]+)/jkl | index 0 or the first key |
/abc/def/ghi/{key}/jkl | /abc/def/ghi/(?P<key>.+)/jkl | key key |
To enable the simple routing pattern, the regexp attribute must be false (not default).
New in version 2.1.
In addition to the simple routing, the default route for /favicon.ico is available if not assigned.
For a routing directive controller, the attribute class is a class reference to a particular controller where the controller must be on the system path (for Python).
<controller class="app.note.controller.IndexController" pattern="/notes/(.*)"/>
For a routing directive redirection, the attribute destination is a string indicating the destination of the redirection, and the attribute permanent is a boolean indicating whether the redirection is permanent.
<redirection destination="/notes/" pattern="/notes"/>
For a routing directive resource, the attribute location is either:
the attribute cache is a boolean to indicate whether the resource should be cache.
<resource location="resources/favicon.ico" pattern="/favicon.ico" cache="true"/>