A closer look at route matching
One of the key parts is the URLRouter
class. You use this class to find a matching route and then run the action associated with this route. Matching follows these rules:
- Routes are compared in the order that they are initially specified.
- If a route matches, then the associate handler is executed.
- Matching stops if a handler writes a response.
- If no matching route is found, then the request is not handled. A 404 error is generated.
You need to specify the HTTP method and the route to match. The match()
method takes the HTTP method, the match string, and the action callback as a parameter. The get()
, post()
, put()
, delete_()
, and patch()
methods take only the match string and the action callback as a parameter and match the HTTP method of the same name. If you do not want to consider the HTTP method, then you use the any()
method to add a match string. This can be useful if you want to log a request or implement some special route handling that is valid for all...