File size: 1,480 Bytes
fc0f7bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
.. _routing:

Routing
=======

The *falcon.routing* module contains utilities used internally by
:py:meth:`falcon.API` to route requests. They are exposed here for use by
custom routing engines.

A custom router is any class that implements the following interface:

.. code:: python

    class FancyRouter(object):
        def add_route(self, uri_template, method_map, resource):
            """Adds a route between URI path template and resource.

            Args:
                uri_template (str): The URI template to add.
                method_map (dict): A method map obtained by calling
                    falcon.routing.create_http_method_map.
                resource (object): Instance of the resource class that
                    will handle requests for the given URI.
            """

        def find(self, uri):
            """Search for a route that matches the given partial URI.

            Args:
                uri(str): The requested path to route

            Returns:
                tuple: A 4-member tuple composed of (resource, method_map,
                    params, uri_template), or ``None`` if no route matches
                    the requested path
            """

A custom routing engine may be specified when instantiating
:py:meth:`falcon.API`. For example:

.. code:: python

    fancy = FancyRouter()
    api = API(router=fancy)

.. automodule:: falcon.routing
    :members: create_http_method_map, compile_uri_template, CompiledRouter