When calling remoteMethod you can add a function to the response directly. This is done using the rest.after option:
function responseStatus(status) { return function(context, callback) { var result = context.result; if(testResult(result)) { // testResult is some method for checking that you have the correct return data context.res.statusCode = status; } return callback(); } } MyModel.remoteMethod('create', { description: 'Create a new object and persist it into the data source', accepts: {arg: 'data', type: 'object', description: 'Model instance data', http: {source: 'body'}}, returns: {arg: 'data', type: mname, root: true}, http: {verb: 'post', path: '/'}, rest: {after: responseStatus(201) } });
Note. It looks like strongloop will cause 204 "No content" if the value of context.result false. To get around this, I just pass an empty {} object with my desired status code.
source share