To add custom actions, today I do this (similar, this is adapted so there may be some simple errors):
var controller = require('users_controller');
var resource = app.resource('users', controller);
var custom_user_actions = [
{
name: 'login',
method: 'get', // or post, put, delete
scope: 'element', // or 'collection'
action: resource.login
}
];
// Constructs /users/:user/login for element-type actions, or /users/recent (for example) for collection-type actions
custom_user_actions.forEach(function(action) {
var path = '';
if('element' == action.scope) {
path = '/' + resource.param;
}
path = path + '/' + action.name;
// Calls resource.get, etc
resource[action.method](path, action.action); // Add with the proper method
});
}
First, is there already a better way to do this? If it makes sense, the forEach could be integrated as a method on the Resource object pretty easily. Other approaches?
To add custom actions, today I do this (similar, this is adapted so there may be some simple errors):
First, is there already a better way to do this? If it makes sense, the forEach could be integrated as a method on the Resource object pretty easily. Other approaches?