Routes
You can easily bind a route path to a controller method. Routes path are defined in the same way as in expressjs router.
Each route class has the following methods:
path- same as in expressjs.method- one ofget,post,patch,delete,put. defaultget.action- the action function the will be invoked to handle the route.middleware- middleware function the will be invoked before the controller. If thenextfunction is not called or called with an error, the controller won`t be created.
Path#
path can be defined with path,get,post,del,put,patch
path can be static string ,dynamic params or regex expressions
Prefix#
prefix to all routes in the controller can be added using @controller([preix]).
@controller("/api/v1/")will add/api/v1/prefix to all routes in this controller
You can return response by using res.send
Create#
You can also define routes using app.route.createRoute
or using discovery
Order#
you can set the route order if 2 route collide.
in the example /test/:id will catch also /test/somepath
we can solve this using the order decorator
Global#
global routes * and / are ordered last
you can catch not found routes using *