Conventions over configuration
App/
controllers/
api/
accountsController.js --> /api/accounts
var mvc = require('node-action-controller');
function AccountsController() {
}
// GET /api/accounts
AccountsController.prototype.list = function() {
};
// GET /api/accounts/:id
AccountsController.prototype.get = function(id) {
};
// alias for AccountsController.get
AccountsController.prototype.index = function(id) {
};
// POST /api/accounts data
AccountsController.prototype.post = function(data) {
};
// alias for AccountsController.post
AccountsController.prototype.create = function(data) {
};
// PUT /api/accounts/:id data
AccountsController.prototype.put = function(id, data) {
};
// alias for AccountsController.put
AccountsController.prototype.update = function(id, data) {
};
// DELETE /api/accounts/:id
AccountsController.prototype.delete = function(id) {
};
// alias for AccountsController.delete
AccountsController.prototype.destroy = function(id) {
};
module.exports = AccountsController;
- path - base path for the controller's actions
- options
- path -
- args -
- before -
- after -
- fn - the controller constructor function
The controller constructor function fn
-
options
- controllerDir - the path to the directory that contains the controller definitions, usually
./controllers
- factory - a function that is used to create the controller objects when needed.
Parameters:
controller - the controller constructor function
context
- controllerDir - the path to the directory that contains the controller definitions, usually
Express.Router object
var action_controller = require('node-action-controller');
app.use('/api/v1/', action_controller.express({
controllerDir: path.join(__dirname, 'controllers'),
factory: function (controller, context) {
}
}));