Navigation

Routr provides a set of tools to map WSGI (WebOb by default) request to an
artbitrary Python object. It was designed with the following points in mind:

Declarativeness – configuration process is designed to be declarative. That
means routes are readable and easy to understand and follow. Routr also
provides a way to automatically generate documentation from routes (via Sphinx
extension).

Extensibility – routing mechanism designed to be extremely extendable, you
can define guards for your routes, provide annotations to them or even
replace parts of routing mechanism by your own implementations.

Composability – routes defined with routr are composable – you can mix and
match them to compose more sofisticated routing structures.

Non-intrusiveness – there are no “frameworkish” things, just a mechanism to
map request to Python object. How to setup request processing is completely up
to you.

As you can see method and pattern are optional here, by default
method will be set to GET and pattern to /. Argument target is
an arbitrary object you want to associate endpoint route with, usually it will
be a view callable or string which specifies one.

You can annotate any route with arbitrary objects, routr.route() accepts
**kwargs arguments and all of those (except name and guards which
have special meaning) will be passed to routr.Route constructor so you
can access it via routr.Trace object after matching:

Note that routr.Trace objects also provide access for parent routes of
endpoint route via Trace.routes attribute so you can accumulate annotations
along the matched path. This, for example, can be useful for implementing
middleware system like Django does but this allows only fire some middleware on
those routes which was annotated correspondingly.

Routr provides a shortcut for defining routes for serving static data, it uses
webob.static under the hood. While this is not a production-ready solution
(I recommend nginx for this) it can be quite useful during development for
serving static assets such as HTML, CSS or javascript.

Note, that handler for these routes accepts only two arguments – request
and path, so you need to distinguish it using static_view annotation
from other target objects and handle call to it separately like this: