{"_id":"connectables","_rev":"7-cca4277ee70646bfa251e0f3fdebb461","name":"connectables","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"connectables","version":"0.0.1","author":{"name":"Damon Oehlman","email":"damon.oehlman@sidelab.com"},"_id":"connectables@0.0.1","maintainers":[{"name":"damonoehlman","email":"damon.oehlman@sidelab.com"}],"contributors":[],"bugs":{"url":"http://github.com/DamonOehlman/connectables/issues"},"dist":{"shasum":"3ebab4650b10574f195674c0d7d9a9ca36d67bd8","tarball":"https://registry.npmjs.org/connectables/-/connectables-0.0.1.tgz","integrity":"sha512-eNtZAGizqPoK5yHcVzVo+v6b7OdqKMsDE+ymYlV1IbSQjGDpkbUuU0Noq/f2t82Lof5wB3L+Nf+Xe15lVch7Ww==","signatures":[{"sig":"MEYCIQDtwpFMUSlThXprT4vrUrJ8xOFJe6MJr+fuangTrTM7BwIhAOxaRc50291yR6SpbIG8zArIEK+UKGMDdQErgF4dfJ1+","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","tags":["connect","middleware","rack"],"engines":{"node":"0.4.x || 0.5.x"},"repository":{"url":"git://github.com/DamonOehlman/connectables.git","type":"git"},"_npmVersion":"1.0.27","description":"Useful middleware for Connect","_nodeVersion":"v0.4.8","_npmJsonOpts":{"file":"/Users/damo/.npm/connectables/0.0.1/package/package.json","wscript":false,"serverjs":false,"contributors":false},"dependencies":{},"_defaultsLoaded":true,"devDependencies":{"vows":"0.5.x","connect":"x.x.x"},"_engineSupported":true,"directories":{}},"0.0.2":{"name":"connectables","description":"Useful middleware for Connect","tags":["connect","middleware","rack"],"author":{"name":"Damon Oehlman","email":"damon.oehlman@gmail.com"},"version":"0.0.2","main":"index","license":"MIT","devDependencies":{"connect":"x.x.x","vows":"0.5.x"},"repository":{"type":"git","url":"git+ssh://git@github.com/DamonOehlman/connectables.git"},"bugs":{"url":"http://github.com/DamonOehlman/connectables/issues"},"_id":"connectables@0.0.2","gitHead":"1bc89bfe9fe6d1d63ce2c85ca1a6577c55d73e16","homepage":"https://github.com/DamonOehlman/connectables#readme","_nodeVersion":"20.12.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-VxALOl4WyDwCWtiayT27wjHT1Dx2u0fv6h90054jdlRAo8+r+v8xlYHByirtOcRJ1v5/WLdEQ3Ah1RAdQZsezg==","shasum":"25ab85e75880d8f8d23f95a988acbe671ff8e5f9","tarball":"https://registry.npmjs.org/connectables/-/connectables-0.0.2.tgz","fileCount":8,"unpackedSize":15926,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDqind4HYmTj0G3m4C8+/hht9SmVNi688g9OAQ1mvhfdAIhAIxrkCIXeS+1SzPZJgqZm+OfNZuAcCrFBzH1FeJG5JtO"}]},"_npmUser":{"name":"damonoehlman","email":"damon.oehlman@gmail.com"},"directories":{},"maintainers":[{"name":"damonoehlman","email":"damon.oehlman@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/connectables_0.0.2_1723077437923_0.7265801031009571"},"_hasShrinkwrap":false}},"time":{"created":"2011-09-19T23:21:11.864Z","modified":"2024-08-08T00:37:18.298Z","0.0.1":"2011-09-19T23:21:13.512Z","0.0.2":"2024-08-08T00:37:18.112Z"},"author":{"name":"Damon Oehlman","email":"damon.oehlman@gmail.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/DamonOehlman/connectables.git"},"description":"Useful middleware for Connect","bugs":{"url":"http://github.com/DamonOehlman/connectables/issues"},"maintainers":[{"name":"damonoehlman","email":"damon.oehlman@gmail.com"}],"readme":"# connectables\n\nMiddleware extras for the excellent [connect](https://github.com/senchalabs/connect) Node.js middleware layer.\n\n## Overview\n\nThis project exists, because particular parts of the connect middleware started to be [removed from the project](https://github.com/senchalabs/connect/issues/262).  While I agree that Connect should be as light as possible, I really don't need some of the functionality that [Express](https://github.com/visionmedia/express) provides and really, really like connect.\n\nSo this project aims to provide a router compatible with the previous connect router middleware, which is [Sinatra](http://www.sinatrarb.com/intro)-like in its route definition and behaviour.  Additionally, I expect that some additional [rack](http://rack.rubyforge.org/)-like middleware will also make an appearance...\n\n## Using the Router\n\nInitializing the router is quite simple and uses the same general approach that the original connect router did, for instance,\n\n```js\nvar server = connect.createServer(\n    connect.logger(),\n    \n    connectables.router(function(router) {\n        router.get('/', function(req, res, next) {\n            res.end('Hi');\n        });\n    })\n);\n```\n\nis an example of a simple route registration, which if you are familiar with the existing connect router should look pretty much exactly the same.\n\n### RESTful URL parameters\n\nIf you are keen to use RESTful urls to drive your web application, then you can register urls that act as parameter values:\n\n```js\nvar server = connect.createServer(\n    connect.logger(),\n    \n    connectables.router(function(router) {\n        router.get('/doc/:id', function(req, res, next) {\n            res.end('You asked for doc id: ' + req.params.id);\n        });\n    })\n);\n```\n\n### Optional Parameters\n\nUsing similar code to what is shown above, you can make parameterized urls with optional parameters:\n\n```js\nvar server = connect.createServer(\n    connect.logger(),\n    \n    connectables.router(function(router) {\n        router.get('/docs/:category?', function(req, res, next) {\n            if (! req.params.category) {\n                res.end('No category specified, guess I should list all the docs');\n            }\n            else {\n                res.end('You asked for the doc category: ' + req.params.category);\n            }\n        });\n    })\n);\n```\n\n### Wildcard Sections\n\nIn similar fashion to Sinatra routes, the connectables router supports wildcards:\n\n```js\nvar server = connect.createServer(\n    connect.logger(),\n    \n    connectables.router(function(router) {\n        router.get('/the/*/*/on/the/*', function(req, res, next) {\n            var splat = req.params['*'],\n                phrase = 'the ' + (splat[0] || '') + ' ' + \n                    (splat[1] || '') + ' ' + \n                    'on the ' + (splat[2] || '');\n            \n            res.end(phrase);\n        });\n    })\n);\n```\nHaving a look at the code above, you can probably see that the multiple wildcard parameter\nmatches are added to the `*` parameter values.  You will also see that in the case above the parameter values are passed back as an array rather than a single value.  This is the default behaviour when multiple parameters with the same name are encountered.\n\n## Query Parameter Handling\n\nThe connectables router patches the request object to supply query string parameters as an object literal.  This might be duplication with core connect and/or node functionality and this is being investigated...\n\n## Alternative Initialization\n\nAn alternative way to use the router and define / remove the routes is to initialize the router without providing the callback function:\n\n```js\nvar connectables = require('connectables'),\n\trouter = connectables.router();\n```\n\nInitializing the router in this way returns the the router instance instead of the request handler function.  You can then reference use this router instance to programmatically add and remove routes as required:\n\n```js\nrouter.get('/', function(req, res, next) {\n\tres.end('Hi again');\n});\n```\n\nYou do of course, still need to register the router as connect middleware though.  This is done by calling the `init` method of the router instance:\n\n```js\nvar server = connect.createServer(\n    connect.logger(),\n    router.init()\n);\n```\n\n## License(s)\n\n### MIT\n\nCopyright (c) 2011 Damon Oehlman <damon.oehlman@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","homepage":"https://github.com/DamonOehlman/connectables#readme","license":"MIT","readmeFilename":"README.md"}