Plumier generate routes directly from controllers. By default it will looks into the
./controller directory. Except other directory or controller classes specified on the configuration.
The main idea of Plumier route generator is generate route based on:
<directories>/<controller name>/<method name>. Further more decorator(s)
@route can be used to customize the generation result
@route decorator provided, route will be generated by convention using controller name, method name and parameter names. By default route by convention will have GET http method.
Route generated based on controller directory hierarchy. For example if the controller hierarchy like below:
Directory convention can be disabled by using
ControllerFacility and set
Note that AnimalController will have their own root route based on their directory.
Http verb override will only override the http verb of the route, route will be constructed using controller name (omit controller word) and action name
Absolute route override (route start with
/) will ignore all the controller and action name including the directory convention name, instead it will used provided route.
Relative route override will only rename the name of the action and keep using controller name.
You can provided empty string on the route parameter to ignore action name
Its possible to use different parameter name on route and the action parameter name like below
Above code means that the
id route parameter will be bound to the
name action parameter. Using this configuration will get rid the route analysis error.
Sum up of above rules you can construct clean Restful API routes like below:
Root route only override the controller name
Relative/Absolute rule also applied into the Root route. When placed inside directory convention, an absolute Root route will skipped the directory name convention.
And logically Relative/Absolute rule, doesn't affected Root route name.
Root route can be parameterized and provided backing parameter on all of the action, except absolute route
Same as the
@route decorator, the
@route.root also provide parameter mapping which work the same
By using rules above you can configure nested restful api like below:
Multiple routes can be applied to an action, this functionalities needed for example when hosting an SPA with url rewrite
A more convenient way to serve SPA url rewrite is using
@route.historyApiFallback() see here for more info
Multiple root routes can also be applied into a controller and resulting create multiple routes for each methods.
Absolute route when combined with multiple root route will cause conflict, consider to avoid them.
By default Route Generation System will generate all methods inside controller into route. In some case you need to create an helper method inside controller but you don't want the method generated into route.
Above code showing that
helper method will not be generated because it is marked with
@route.ignore() can be applied on controller and make all routes inside controller ignored completely. This feature important on CRUD Route generation, where controller automatically generated and you don't have control to the controller.
Above code will cause all routes inside
HomeController ignored completely.
If you have a controller with inheritance, you can ignore super class routes by specifying method name like below
Above code showing that we ignore the
replace method which cause only
GET /users/get will be generated.