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();
Or:
return res.created(data);
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:
data
as JSON. If no data
is provided a default response body will be sent (the string "Created"
).pathToView
was provided, Sails will attempt to use that view.pathToView
was not provided, Sails will attempt to guess the appropriate response view. If that view does not exist, Sails will just send JSON.data
argument will be accessible as a view local: data
.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
return
throughout 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 acreated.js
response method does not exist in your app, Sails will implicitly use the default behavior.- If
pathToView
refers to a missing view, this method will respond as if the request "wants JSON".