View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

Create (Blueprint)

Create a new record in your database.

POST /:model

Responds with a JSON dictionary representing the newly created instance. If a validation error occurred, a JSON response with the invalid attributes and a 400 status code will be returned instead.

Additionally, a create event will be published to all listening sockets (see the docs for .watch() for more info).

If the action is triggered via a socket request, the requesting socket will ALSO be subscribed to the newly created model instance. If the record is subsequently updated or deleted, a message will be sent to that socket's client informing them of the change. See the docs for .subscribe() for more info.

Parameters

Parameters should be sent in the request body. By default, Sails understands most common types of encodings for body parameters, including url-encoding, form-encoding, and JSON.

Parameter Type Details
* Send body parameters with the same names as the attribute defined on your model to set those values on your new record.

These values are handled the same way as if they were passed into the model's .create() method.
callback If specified, a JSONP response will be sent (instead of JSON). This is the name of the client-side javascript function to call, passing results as the first (and only) argument

e.g. ?callback=myJSONPHandlerFn

Example

Create a new pony named "AppleJack" with a hobby of "pickin":

POST /pony
{
  "name": "AppleJack",
  "hobby": "pickin"
}
Example Response
{
  "name": "AppleJack",
  "hobby": "pickin",
  "id": 47,
  "createdAt": "2013-10-18T01:23:56.000Z",
  "updatedAt": "2013-11-26T22:55:19.951Z"
}

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-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book