I have created a new Sails app, and so far I have created an api using sails generate api guitar, and then added this code in the controller:
module.exports = {
fender: function(req, res){
console.log(req.params);
res.notFound();
}
};
As expected, when I go to http://localhost:1337/guitar/fender I get a 404 error (that's the response I programed). But what I don't get is, if I go to http://localhost:1337/guitar/fender/4, the console will show [ id: '4' ]. I seems that somewhere there's a GET /guitar/fender/:id (using Express/Rails syntax here) sort of URL. But I don't see it anywhere, not in config/routes.js or anywhere else.
So, does Sails.js create a :id for every controller action automatically? Or am I missing something here?
I tried some things, such as adding this to the config/routes.js file:
'get /guitar/fender/:brand': 'GuitarController.fender'
And then when I go to the URL again, [ brand: '4' ] will be printed instead of id.
So my final question is: Does Sails.js automatically make an :id for every controller action?
(I couldn't find this on the docs either)
via Felo Vilches
No comments:
Post a Comment