Routes¶
Router¶
-
class
dragonfly.routes.router.
Router
¶ Bases:
object
Routes the given route to the defined ``Controller``and returns its generated
Response
.-
add_route
(uri, action, method)¶ Adds a route to the RouteCollection object.
Parameters: - uri (str) – The URI of the route
- action (str) – The action of the route e.g ‘HomeController@home’
- method (str) – The HTTP method verb e.g ‘GET’
-
any
(uri, action)¶
-
delete
(uri, action)¶
-
dispatch_route
()¶ Dispatches the appropriate route based on the request method and path.
-
get
(uri, action)¶
-
options
(uri, action)¶
-
patch
(uri, action)¶
-
post
(uri, action)¶
-
put
(uri, action)¶
-
resource
(uri, controller)¶
-
-
dragonfly.routes.router.
to_snake
(name)¶ From StackOverflow https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
Warning
The following classes should not be called directly.
RouteCollection¶
-
class
dragonfly.routes.route_collection.
RouteCollection
¶ Bases:
object
A way to store registered routes.
-
add
(uri, action, method)¶ Add a new route to either the static or dynamic routes dictionary.
Parameters: - uri (str) – The route uri
- action (str) – The route action
- method (str) – The route HTTP method
-
match_route
(uri, method)¶ Match the given route using its URI and method. First we check if it is a static route before checking all dynamic routes.
Parameters: - uri (str) – The URI to match
- method (str) – The HTTP method
Returns: Any matching routes
Type: dict
-
RouteRule¶
-
class
dragonfly.routes.route_rule.
RouteRule
(uri)¶ Bases:
object
Data structure to store dynamic routes. Allows for an easy check of whether a given route matches a dynamic route.
-
match
(uri)¶ Matches the given route to an action and extracts any router parameters.
Parameters: uri (str) – The URI to match. Returns: A dictionary containing the the action and any route parameters. Return type: dict
-