kongadmin
Version:
Kong admin GUI
35 lines (29 loc) • 889 B
JavaScript
;
/**
* 201 (CREATED) Response
*
* Usage:
* return res.created();
* return res.created(data);
* return res.created(data, 'auth/login');
*
* @param {{}} data Data for response
* @param {{}} options Response options
* @returns {*}
*/
module.exports = function created(data, options) {
// Get access to `req`, `res`, & `sails`
var request = this.req;
var response = this.res;
var sails = request._sails;
/**
* If second argument is a string, we take that to mean it refers to a view.
* If it was omitted, use an empty object (`{}`)
*/
options = (typeof options === 'string') ? {view: options} : options || {};
sails.log.silly('res.created() :: Sending 201 ("CREATED") response');
// Set status code
response.status(201);
// Backend will always response JSON
return response.jsonx(data);
};