This method is used to send a 201 ("Created") response back down to the client indicating that one or more resources have been successfully created.
return res.created(data, pathToView);
Like the other built-in custom response modules, the behavior of this method is customizable.
By default, it works as follows:
dataas JSON. If no
datais provided a default response body will be sent (the string
pathToViewwas provided, Sails will attempt to use that view.
pathToViewwas not provided, Sails will attempt to guess the appropriate response view. If that view does not exist, Sails will just send JSON.
dataargument will be accessible as a view local:
Using the default view:
return res.created('New widget created.');
With a custom view:
return res.created( 'New widget created.', 'widgets/created' );
- This method is terminal, meaning it is generally the last line of code your app should run for a given request (hence the advisory usage of
returnthroughout these docs).
res.created()(like other userland response methods) can be overridden or modified. It runs the response method defined in
/responses/created.js, which is bundled automatically in newly generated Sails apps. If a
created.jsresponse method does not exist in your app, Sails will implicitly use the default behavior.
pathToViewrefers to a missing view, this method will respond as if the request "wants JSON".