{"_id":"express-controllers","_rev":"7-81d04787f92cac3972f48ba63e6a299c","name":"express-controllers","description":"Dead simple MVC routing for express","dist-tags":{"latest":"1.0.0"},"versions":{"0.2.0":{"name":"express-controllers","description":"MVC routing for express","version":"0.2.0","author":{"name":"Nicholas Penree","email":"drudge@conceited.net"},"repository":{"type":"git","url":"git://github.com/drudge/express-controllers.git"},"contributors":[],"dependencies":{"express-resource":">=0.2.1"},"devDependencies":{"connect":"1.4.x","express":"2.3.x"},"keywords":["express","rest","resource","mvc","controller"],"main":"index","engines":{"node":">= 0.2.0"},"_id":"express-controllers@0.2.0","_engineSupported":true,"_npmVersion":"1.0.5","_nodeVersion":"v0.4.8","_defaultsLoaded":true,"dist":{"shasum":"e9d3436c0309a258e610f995553299c517cacac8","tarball":"https://registry.npmjs.org/express-controllers/-/express-controllers-0.2.0.tgz","integrity":"sha512-+asyxVvvsPBYFZeCPAxi1ip5HndOHviC7/GSL15R+kkWu/okedD/Roo1U/HmfdQhZkCgD5/EuS8s4izY6s9JcQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDWG2759NCc8KuT4/mAYgQLT0EKuzhu+Sv+hv6gfzffegIgcEjEzIVGa6c/RK59AnxTelzsEvQkTu0CFn4Y6YM9Sws="}]},"scripts":{}},"1.0.0":{"name":"express-controllers","description":"Dead simple MVC routing for express","version":"1.0.0","author":{"name":"Nicholas Penree","email":"nick@penree.com"},"repository":{"type":"git","url":"git://github.com/drudge/express-controllers.git"},"contributors":[],"dependencies":{"express-resource":"~1.0.0"},"devDependencies":{"express":"4.x.x"},"keywords":["express","rest","resource","mvc","controller"],"main":"index","engines":{"node":">= 0.8.0"},"gitHead":"ed8c30252020b1eeb0fc3b101001cd5b00e15689","bugs":{"url":"https://github.com/drudge/express-controllers/issues"},"homepage":"https://github.com/drudge/express-controllers","_id":"express-controllers@1.0.0","scripts":{},"_shasum":"dce3f4b86ac937a5df805f3a56d0ff6a6af836ec","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"drudge","email":"nick@penree.com"},"maintainers":[{"name":"drudge","email":"drudge@conceited.net"}],"dist":{"shasum":"dce3f4b86ac937a5df805f3a56d0ff6a6af836ec","tarball":"https://registry.npmjs.org/express-controllers/-/express-controllers-1.0.0.tgz","integrity":"sha512-s8O6rEF8K1zjtC/f1qmkf8VZ0FlL3y5DvnLJRilcxVAozNrlrZ7JuweBBPqtwEFB/TonTJT5Q1XzwW7JCJmjxw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCE1rP3Rv8oAMRLZqLESJOMXth9GZ0DMvHhYIgoYanHogIhAPyO4PDY9XL73FHIOjEISYu8hNvL7YGFTWHP0nK+aWPB"}]}}},"maintainers":[{"name":"drudge","email":"drudge@conceited.net"}],"time":{"modified":"2022-06-17T22:13:07.879Z","created":"2011-05-27T02:14:40.058Z","0.2.0":"2011-05-27T02:14:40.351Z","1.0.0":"2014-11-30T19:37:48.929Z"},"author":{"name":"Nicholas Penree","email":"nick@penree.com"},"repository":{"type":"git","url":"git://github.com/drudge/express-controllers.git"},"readme":"[![build status](https://secure.travis-ci.org/drudge/express-controllers.png)](http://travis-ci.org/drudge/express-controllers)\n# Express Controllers\n\n  express-controllers adds controller style routing from the model-view-controller paradigm to express using [express-resource](http://github.com/visionmedia/express-resource).\n\n## Installation\n\nnpm:\n\n    $ npm install express-controllers\n\n## Usage\n\n```js\nvar express = require('express')\nvar controllers = require('express-controllers')\n\nvar app = module.exports = express().controllers();\n\nif (!require.parent) {\n  var server = app.listen(3000, function() {\n    var host = server.address().address;\n    var port = server.address().port;\n    console.log('Express 4 server listening at http://%s:%s', host, port);\n  });\n}\n```\n\nBy default, the `app.controllers()` method will load any controllers in the directory named `controllers` of your application (wherever server.js/app.js is). If you prefer to store your controllers in a different location, simply specify your desired path in the app setting via `app.set('controllers path', '/path/to/controllers/')`.\n\n\n To get started simply `require('express-controllers')`, and this module will monkey-patch Express, enabling the controller style routing by providing the `app.controllers()` method. \n \n### Controllers\n  \n  A \"controller\" is simply a module which defines one of more of the supported \"actions\", listed below:\n\n```js\nexports.index = function(req, res) {\n  res.send('forum index');\n};\n\nexports.new = function(req, res) {\n  res.send('new forum');\n};\n\nexports.create = function(req, res) {\n  res.send('create forum');\n};\n\nexports.show = function(req, res) {\n  res.send('show forum ' + req.params.forum);\n};\n\nexports.edit = function(req, res) {\n  res.send('edit forum ' + req.params.forum);\n};\n\nexports.update = function(req, res) {\n  res.send('update forum ' + req.params.forum);\n};\n\nexports.destroy = function(req, res) {\n  res.send('destroy forum ' + req.params.forum);\n};\n```\n\n### Default Action Mapping\n\nActions are then mapped as follows (by default), providing `req.params.forum` which contains the substring where \":forum\" is shown below:\n\n    GET     /forums              ->  index\n    GET     /forums/new          ->  new\n    POST    /forums              ->  create\n    GET     /forums/:forum       ->  show\n    GET     /forums/:forum/edit  ->  edit\n    PUT     /forums/:forum       ->  update\n    DELETE  /forums/:forum       ->  destroy\n\n### Content-Negotiation\n\n  Currently express-controllers (by way of express-resource) supports basic content-negotiation support utilizing extnames or \"formats\". This can currently be done two ways, first we may define actions as we normally would, and utilize the `req.format` property, and respond accordingly. The following would respond to `GET /pets.xml`, and `GET /pets.json`.\n  \n```js\nvar pets = ['tobi', 'jane', 'loki'];\n\nexports.index = function(req, res) {\n  switch (req.format) {\n    case 'json':\n      res.send(pets);\n      break;\n    case 'xml':\n      res.send('<pets>' + pets.map(function(pet) {\n        return '<pet>' + pet + '</pet>';\n      }).join('') + '</pets>');\n      break;\n    default:\n      res.send(406);\n  }\n};\n```\n\n The following is equivalent, however we separate the logic into several callbacks, each representing a format. \n \n```js\nexports.index = {\n  json: function(req, res) {\n    res.send(pets);\n  },\n\n  xml: function(req, res){\n    res.send('<pets>' + pets.map(function(pet) {\n     return '<pet>' + pet + '</pet>';\n    }).join('') + '</pets>');\n  }\n};\n```\n\n We may also provide a `default` format, invoked when either no extension is given, or one that does not match another method is given:\n \n ```js\n exports.default = function(req, res) {\n   res.send('Unsupported format \"' + req.format + '\"', 406);\n };\n```\n\n## License\n\n    The MIT License\n\n    Copyright (c) 2011-2014 Nicholas Penree <nick@penree.com>\n\n    Permission is hereby granted, free of charge, to any person obtaining\n    a copy of this software and associated documentation files (the\n    'Software'), to deal in the Software without restriction, including\n    without limitation the rights to use, copy, modify, merge, publish,\n    distribute, sublicense, and/or sell copies of the Software, and to\n    permit persons to whom the Software is furnished to do so, subject to\n    the following conditions:\n\n    The above copyright notice and this permission notice shall be\n    included in all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\n    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","homepage":"https://github.com/drudge/express-controllers","keywords":["express","rest","resource","mvc","controller"],"contributors":[],"bugs":{"url":"https://github.com/drudge/express-controllers/issues"},"readmeFilename":"README.markdown"}