Edit Page

Routing to actions

Manual routing

#

By default, controller actions in your Sails app will be inaccessible to users until you bind them to a route in your config/routes.js file. When you bind a route, you specify a URL that users can access the action at, along with options like CORS security settings.

To bind a route to an 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 action identity as the value (i.e. the route target).

For example, the following manual route will cause your app to trigger the make action in api/controllers/SandwichController.js whenever it receives a POST request to /make/a/sandwich:

'POST /make/a/sandwich': 'SandwichController.make'

If you’re using standalone actions, so that you had an api/controllers/sandwich/make.js file, a more intuitive syntax exists which uses the path to the action (relative to api/controllers):

'POST /make/a/sandwich': 'sandwich/make'

For a full discussion of routing, please see the routes documentation.

Automatic routing

#

Sails can also automatically bind routes to your controller actions so that a GET request to /:actionIdentity will trigger the action. This is called blueprint action routing, and it can be activated by setting actions to true in the config/blueprints.js file. For example, with blueprint action routing turned on, a signup action saved in api/controllers/UserController.js or api/controllers/user/signup.js would be bound to a /user/signup route. See the blueprints documentation for more information about Sails’ automatic route binding.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Concepts