{"_id":"express-resource","_rev":"220109","name":"express-resource","description":"Resourceful routing for express","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"time":{"modified":"2021-06-03T15:39:29.000Z","created":"2011-02-25T17:15:02.390Z","1.0.0":"2012-10-06T21:46:33.727Z","0.2.4":"2011-12-28T23:44:50.913Z","0.2.3":"2011-09-23T15:14:53.599Z","0.2.2":"2011-09-08T22:56:50.271Z","0.2.1":"2011-05-25T21:12:25.178Z","0.2.0":"2011-04-10T04:49:51.109Z","0.1.0":"2011-03-29T20:26:15.566Z","0.0.2":"2011-03-04T00:04:38.603Z","0.0.1":"2011-02-25T17:15:02.390Z"},"users":{"gdbtek":true,"jerone":true,"lea_io":true,"tomi77":true,"fgribreau":true,"ssh0702":true,"ivangaravito":true,"j3kz":true,"hckhanh":true,"wagnercsfilho":true,"antixrist":true},"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"versions":{"1.0.0":{"name":"express-resource","description":"Resourceful routing for express","version":"1.0.0","homepage":"https://github.com/visionmedia/express-resource","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"contributors":[{"name":"Daniel Gasienica","email":"daniel@gasienica.ch"}],"dependencies":{"lingo":">= 0.0.4","methods":"0.0.1","debug":"*"},"devDependencies":{"connect":"2.x","express":"3.x","ejs":"0.4.x","qs":"0.1.x","mocha":"*","should":"*","supertest":"0.1.2"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":"*"},"_id":"express-resource@1.0.0","dist":{"shasum":"a7148c09f051cc03bcb800cbd16ab155231974cd","size":6411,"noattachment":false,"key":"/express-resource/-/express-resource-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-1.0.0.tgz"},"_npmVersion":"1.1.61","_npmUser":{"name":"tjholowaychuk","email":"tj@vision-media.ca"},"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"directories":{},"publish_time":1349559993727,"_cnpm_publish_time":1349559993727,"_hasShrinkwrap":false},"0.2.4":{"name":"express-resource","description":"Resourceful routing for express","version":"0.2.4","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"contributors":[{"name":"Daniel Gasienica","email":"daniel@gasienica.ch"}],"dependencies":{"lingo":">= 0.0.4"},"devDependencies":{"connect":"1.8.x","express":"2.5.x","ejs":"0.4.x","expresso":"0.9.x","qs":"0.1.x","should":"*"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_npmUser":{"name":"tjholowaychuk","email":"tj@vision-media.ca"},"_id":"express-resource@0.2.4","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"b6be694cba429708f49121c3b99e8e4e4a7e1d9c","size":10240,"noattachment":false,"key":"/express-resource/-/express-resource-0.2.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.2.4.tgz"},"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"directories":{},"publish_time":1325115890913,"_cnpm_publish_time":1325115890913,"_hasShrinkwrap":false},"0.2.3":{"name":"express-resource","description":"Resourceful routing for express","version":"0.2.3","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"contributors":[{"name":"Daniel Gasienica","email":"daniel@gasienica.ch"}],"dependencies":{"lingo":">= 0.0.4"},"devDependencies":{"connect":"1.4.x","express":"2.3.x","ejs":"0.4.x","expresso":"0.7.x","lingo":"0.0.4","qs":"0.1.x","should":">= 0.0.1"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_npmJsonOpts":{"file":"/Users/tj/.npm/express-resource/0.2.3/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"express-resource@0.2.3","_engineSupported":true,"_npmVersion":"1.0.24","_nodeVersion":"v0.4.12","_defaultsLoaded":true,"dist":{"shasum":"cbc020a3d577b5734acbb0a5bb08393d765a338e","size":8395,"noattachment":false,"key":"/express-resource/-/express-resource-0.2.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.2.3.tgz"},"scripts":{},"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"directories":{},"publish_time":1316790893599,"_cnpm_publish_time":1316790893599,"_hasShrinkwrap":false},"0.2.2":{"name":"express-resource","description":"Resourceful routing for express","version":"0.2.2","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"contributors":[{"name":"Daniel Gasienica","email":"daniel@gasienica.ch"}],"dependencies":{"lingo":">= 0.0.4"},"devDependencies":{"connect":"1.4.x","express":"2.3.x","ejs":"0.4.x","expresso":"0.7.x","lingo":"0.0.4","qs":"0.1.x","should":">= 0.0.1"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_npmJsonOpts":{"file":"/Users/tj/.npm/express-resource/0.2.2/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"express-resource@0.2.2","_engineSupported":true,"_npmVersion":"1.0.24","_nodeVersion":"v0.4.11","_defaultsLoaded":true,"dist":{"shasum":"649faf3b71ca2d30194a11de504a61a5a9c32c33","size":8247,"noattachment":false,"key":"/express-resource/-/express-resource-0.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.2.2.tgz"},"scripts":{},"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"directories":{},"publish_time":1315522610271,"_cnpm_publish_time":1315522610271,"_hasShrinkwrap":false},"0.2.1":{"name":"express-resource","description":"Resourceful routing for express","version":"0.2.1","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"contributors":[{"name":"Daniel Gasienica","email":"daniel@gasienica.ch"}],"dependencies":{"lingo":">= 0.0.4"},"devDependencies":{"connect":"1.4.x","express":"2.3.x","ejs":"0.4.x","expresso":"0.7.x","lingo":"0.0.4","qs":"0.1.x","should":">= 0.0.1"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_id":"express-resource@0.2.1","_engineSupported":true,"_npmVersion":"1.0.3","_nodeVersion":"v0.4.8","_defaultsLoaded":true,"dist":{"shasum":"e9c8187e5edf3b9bc5ccc97d2b8798461fba5a10","size":5977,"noattachment":false,"key":"/express-resource/-/express-resource-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.2.1.tgz"},"scripts":{},"directories":{},"publish_time":1306357945178,"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"_cnpm_publish_time":1306357945178,"_hasShrinkwrap":false},"0.2.0":{"name":"express-resource","description":"Resourceful routing for express","version":"0.2.0","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"contributors":[{"name":"Daniel Gasienica","email":"daniel@gasienica.ch"}],"dependencies":{"lingo":">= 0.0.4"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_id":"express-resource@0.2.0","_engineSupported":true,"_npmVersion":"0.3.15","_nodeVersion":"v0.4.5","directories":{},"files":[""],"_defaultsLoaded":true,"dist":{"shasum":"b1c43e6cd3833a86cba2669213a5a0f0003d8154","size":5168,"noattachment":false,"key":"/express-resource/-/express-resource-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.2.0.tgz"},"publish_time":1302410991109,"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"_cnpm_publish_time":1302410991109,"_hasShrinkwrap":false},"0.1.0":{"name":"express-resource","description":"Resourceful routing for express","version":"0.1.0","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"contributors":[{"name":"Daniel Gasienica","email":"daniel@gasienica.ch"}],"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_id":"express-resource@0.1.0","_engineSupported":true,"_npmVersion":"0.3.15","_nodeVersion":"v0.4.3","directories":{},"files":[""],"_defaultsLoaded":true,"dist":{"shasum":"d41e058c55abdc705f76eee04e6fe3d12214e2ad","size":2815,"noattachment":false,"key":"/express-resource/-/express-resource-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.1.0.tgz"},"publish_time":1301430375566,"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"_cnpm_publish_time":1301430375566,"_hasShrinkwrap":false},"0.0.2":{"name":"express-resource","description":"Resourceful routing for express","version":"0.0.2","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_id":"express-resource@0.0.2","_engineSupported":true,"_npmVersion":"0.3.13","_nodeVersion":"v0.4.2","directories":{},"files":[""],"_defaultsLoaded":true,"dist":{"shasum":"632f772ca96da9a0c838a05af82c4629889340c5","size":2606,"noattachment":false,"key":"/express-resource/-/express-resource-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.0.2.tgz"},"publish_time":1299197078603,"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"_cnpm_publish_time":1299197078603,"_hasShrinkwrap":false},"0.0.1":{"name":"express-resource","description":"Resourceful routing for express","version":"0.0.1","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"keywords":["express","rest","resource"],"main":"index","engines":{"node":">= 0.2.0"},"_id":"express-resource@0.0.1","_engineSupported":true,"_npmVersion":"0.2.18","_nodeVersion":"v0.2.6","directories":{},"files":[""],"_defaultsLoaded":true,"dist":{"shasum":"f8de6d2ac5cddcf7c7de042be8ac92b13282010b","size":2973,"noattachment":false,"key":"/express-resource/-/express-resource-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/express-resource/download/express-resource-0.0.1.tgz"},"publish_time":1298654102390,"maintainers":[{"name":"tjholowaychuk","email":"tj@vision-media.ca"}],"_cnpm_publish_time":1298654102390,"_hasShrinkwrap":false}},"readme":"# Express Resource\n\n  express-resource provides resourceful routing to express. For Express 2.x\n  use a version __below__ 1.0, for Express 3.x use 1.x.\n\n## Installation\n\nnpm:\n\n    $ npm install express-resource\n\n## Usage\n\n To get started simply `require('express-resource')`, and this module will monkey-patch Express, enabling resourceful routing by providing the `app.resource()` method. A \"resource\" is simply an object, which defines one of more of the supported \"actions\" listed below:\n\n    exports.index = function(req, res){\n      res.send('forum index');\n    };\n\n    exports.new = function(req, res){\n      res.send('new forum');\n    };\n\n    exports.create = function(req, res){\n      res.send('create forum');\n    };\n\n    exports.show = function(req, res){\n      res.send('show forum ' + req.params.forum);\n    };\n\n    exports.edit = function(req, res){\n      res.send('edit forum ' + req.params.forum);\n    };\n\n    exports.update = function(req, res){\n      res.send('update forum ' + req.params.forum);\n    };\n\n    exports.destroy = function(req, res){\n      res.send('destroy forum ' + req.params.forum);\n    };\n\nThe `app.resource()` method returns a new `Resource` object, which can be used to further map pathnames, nest resources, and more.\n\n    var express = require('express')\n      , Resource = require('express-resource')\n      , app = express.createServer();\n\n    app.resource('forums', require('./forum'));\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## Top-Level Resource\n\nSpecify a top-level resource by omitting the resource name:\n\n    app.resource(require('./forum'));\n\nTop-level actions are then mapped as follows (by default):\n\n    GET     /                 ->  index\n    GET     /new              ->  new\n    POST    /                 ->  create\n    GET     /:id              ->  show\n    GET     /:id/edit         ->  edit\n    PUT     /:id              ->  update\n    DELETE  /:id              ->  destroy\n\n## Auto-Loading\n\nResources have the concept of \"auto-loading\" associated data. For example we can pass a \"load\" property along with our actions, which should invoke the callback function with an error, or the object such as a `User`:\n\n\n      User.load = function(id, fn) {\n        fn(null, users[id]);\n      };\n\n      // or\n      \n      User.load = function(req, id, fn) {\n        fn(null, users[id]);\n      };\n\n      app.resource('users', { show: ..., load: User.load });\n      \n With the auto-loader defined, the `req.user` object will be available now be available to the actions automatically. We may pass the \"load\" option as the third param as well, although this is equivalent to above, but allows you to either export \".load\" along with your actions, or passing it explicitly:\n \n     app.resource('users', require('./user'), { load: User.load });\n\n Finally we can utilize the `Resource#load(fn)` method, which again is functionally equivalent:\n \n     var user = app.resource('users', require('./user'));\n     user.load(User.load);\n\n  This functionality works when nesting resources as well, for example suppose we have a forum, which contains threads, our setup may look something like below:\n  \n      var forums = app.resource('forums', require('resources/forums'), { load: Forum.get });\n      var threads = app.resource('threads', require('resources/threads'), { load: Thread.get });\n\n      forums.add(threads);\n\n  Now when we request `GET /forums/5/threads/12` both the `req.forum` object, and `req.thread` will be available to thread's _show_ action.\n\n## Content-Negotiation\n\n  Currently 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      var pets = ['tobi', 'jane', 'loki'];\n\n      exports.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 The following is equivalent, however we separate the logic into several callbacks, each representing a format. \n \n     exports.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 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 \n     exports.default = function(req, res){\n       res.send('Unsupported format \"' + req.format + '\"', 406);\n     };\n\n To assign a default format to an existing method, we can provide the `format` option to the resource. With the following definition both `GET /users/5` and `GET /users/5.json` will invoke the `show.json` action, or `show` with `req.format = 'json'`.\n \n     app.resource('users', actions, { format: 'json' });\n\n## Running Tests\n\nFirst make sure you have the submodules:\n\n    $ git submodule update --init\n\nThen run the tests:\n\n    $ make test\n\n## License\n\n    The MIT License\n\n    Copyright (c) 2010-2012 TJ Holowaychuk <tj@vision-media.ca>\n    Copyright (c) 2011 Daniel Gasienica <daniel@gasienica.ch>\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","_attachments":{},"homepage":"https://github.com/visionmedia/express-resource"}