By default, Sails will create a blueprint action route for each action in a controller, so that a GET request to /:controllerIdentity/:nameOfAction will trigger the action. If the example controller in the previous section was saved as api/controllers/SayController.js, then the /say/hi and /say/bye routes would be made available by default whenever the app was lifted. If the controller was saved under the subfolder /we, then the routes would be /we/say/hi and /we/say/bye. See the blueprints documentation for more information about Sails’ automatic route binding.
Besides the default routing, Sails allows you to manually bind routes to controller actions using the config/routes.js file. Some examples of when you might want to use explicit routes are:
GET, POST, PUT, DELETE, etc.PUT /login, POST /signup, or a "vanity URL" like GET /:username)To manually bind a route to a controller action in the config/routes.js file, you can use the HTTP verb and path (i.e. the route address) as the key, and the controller name + . + action name as the value (i.e. the route target).
For example, the following manual route will cause your app to trigger the makeIt() action in api/controllers/SandwichController.js whenever it receives a POST request to /make/a/sandwich:
'POST /make/a/sandwich': 'SandwichController.makeIt'
Note:
For controller files saved in subfolders, the subfolder is part of the controller identity:
'/do/homework': 'stuff/things/HomeworkController.do'This will cause the
do()action inapi/controllers/stuff/things/HomeworkController.jsto be triggered whenever/do/homeworkis requested.
A full discussion of manual routing is out of the scope of this doc--please see the routes documentation for a full overview of the available options.