Say I have a ShoppingCart
model with a one-to-many relation to an Item
model (ie A shopping cart can be full of different items).
I can obviously create a new shopping cart like so:
POST /api/shoppingcart
What I'd like to create is a RESTful API where an item can be added (or updated) to that shopping cart like this:
POST /api/shoppingcart/:shoppingCartId/item
PUT /api/shoppingcart/:shoppingCartId/item/:itemId
From the research I've done so far this doesn't seem built-in to SailsJS. I'd prefer to stay away from manually setting these routes. Is there a way I can automate the route with the ShoppingCartController
?
Never mind, found out Sails does it as long as you have the config rest
option enabled.
It works with GET
, POST
, and DELETE
methods.
[parentModel]/:parentid/[childModel]/:id?
Check the source: https://github.com/balderdashy/sails/blob/master/lib/hooks/blueprints/index.js#L319
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.