Sendero Controllers
Controllers are specified in a special type of file with the .dc extension and then compiled into regular d-code using the sendero controller compiler (senderocc). Here is an example of a controller:
module test.controller.Main; import test.controller.User; controller MainCtlr { GET /() { //controller body goes here } POST login(char[] username, char[] pswd) { //... } GET search(char[] q) { //... } ALL user -> UserCtlr; //... }
Sendero's routing system automatically extracts and converts the http parameters into D-variables using the argument names that you specify in your controller function's declaration and calls that function, making sure that the appropriate HTTP request method was used.
Available controller modifiers:
- GET - routes GET requests to this controller
- POST - routes POST requests to this controller
- ALL - routes requests that are either GET or POST to this controller
- ERROR - specifies an error handler for this controller.
- STATIC - declares the functions as static and registers at as an available controller, but does no routing. This can be used to route a path from another controller to this method. For instance Main.login can be routed to User.login and User.login can be declared as static.
Additional routing methods such as PUT, DELETE, etc. may be added in the future.
