Reputation: 72865
I'm working through the documentation on Sails.js, and have created a basic dev instance according to their "Getting Started" guide:
$ sudo npm -g install sails
$ sails new testProject
$ sails generate users
$ sails lift
These four simple commands will install the platform, create a project, and create the model users
as designed.
From my browser, using the default installation port, I can now access http://localhost:1337/users
and receive an empty JSON array []
as expected.
Now, should I wish to create a new user, REST best practice dictates that I should use the POST
method. POST
does indeed work, however out of the box, Sails also allows you to perform GET http://localhost:1337/users/create
to generate a new user object.
Reading through their documentation, I have been unable to determine a way of limiting which HTTP methods are allowed to perform various tasks. Is this in the documentation? Or can someone explain where in the Sails stack this (should|could) be managed?
Upvotes: 3
Views: 1403
Reputation: 9025
Sails.js provides you with those shortcuts letting you to operate using only GET method for development purposes only. You can disable those in production, if you want, using the configuration noted in the docs:
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 asapi/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:
- When you want to use separate actions to handle the same route path, based on the HTTP method (aka verb). The aforementioned action blueprint routes bind all request methods for a path to a given action, including GET, POST, PUT, DELETE, etc.
Upvotes: 5