How to use blueprint APIs
RESTful blueprint routes
REST blueprints are the automatically generated routes Sails uses to expose a conventional REST API for a model, including
destroy actions. The path for RESTful routes is always
/:modelIdentity/:id. These routes use the HTTP "verb" to determine the action to take.
For example, with rest enabled, having a Boat model in your app generates the following routes:
- GET /boat -> find boats matching criteria provided on the query string, using the find blueprint.
- GET /boat/:id -> find a single boat with the given unique ID (i.e. primary key) value, using the findOne blueprint.
- POST /boat -> create a new boat with the attributes provided in the request body, using the create blueprint.
- PATCH /boat/:id -> update the boat with the given unique ID with the attributes provided in the request body, using the update blueprint.
- DELETE /boat/:id -> destroy the boat with the given unique ID, using the destroy blueprint.
If the Boat model has a “to-many” relationship with a Driver model through an attribute called drivers, then the following additional routes would be available:
- PUT /boat/:id/drivers/:fk -> add the driver with the unique ID equal to the :fk value to the drivers collection of the boat with the ID given as :id, using the add blueprint.
- DELETE /boat/:id/drivers/:fk -> remove the driver with the unique ID equal to the :fk value to the drivers collection of the boat with the ID given as :id, using the remove blueprint
- PUT /boat/:id/drivers -> replace the entire drivers collection with the drivers whose unique IDs are contained in an array provided as the body of the request, using the replace blueprint.
Ref: Sails blueprint routes