{"_id":"dispatch","_rev":"23-746d758bc89a1c1a13c19adb7514e785","name":"dispatch","description":"A regular expression URL dispatcher for Connect","dist-tags":{"latest":"1.0.2"},"versions":{"0.0.1":{"name":"dispatch","description":"A regular expression URL dispatcher for Connect","main":"./index","author":{"name":"Caolan McMahon"},"version":"0.0.1","repository":{"type":"git","url":"http://github.com/caolan/dispatch.git"},"bugs":{"web":"http://github.com/caolan/dispatch/issues"},"licenses":[{"type":"MIT","url":"http://github.com/caolan/dispatch/raw/master/LICENSE"}],"_id":"dispatch@0.0.1","engines":{"node":"*"},"_nodeSupported":true,"_npmVersion":"0.2.7-2","_nodeVersion":"v0.3.1-pre","dist":{"tarball":"https://registry.npmjs.org/dispatch/-/dispatch-0.0.1.tgz","shasum":"dbbb57273457a84afe2d16339433fe77b6e30b52","integrity":"sha512-/p2KUznEbwWeLwH1PtokN35QRmCvhMG8bMJB8y4dA8jwwa4sKDmZv2WoZXt0PFpooEZNK7bJxf8qjkjQPMQZtA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAJkSNmpc3/ox0DKDTPRibS7GZffVGnKyBb8PgcSCZwkAiEArhcPl6dNf5ilqPKhCJEM+Vx2fvdMX6SqafUbtLWx6jA="}]},"directories":{}},"0.2.0":{"name":"dispatch","description":"A regular expression URL dispatcher for Connect","main":"./index","author":{"name":"Caolan McMahon"},"version":"0.2.0","repository":{"type":"git","url":"git://github.com/caolan/dispatch.git"},"bugs":{"url":"http://github.com/caolan/dispatch/issues"},"licenses":[{"type":"MIT","url":"http://github.com/caolan/dispatch/raw/master/LICENSE"}],"_npmUser":{"name":"caolan","email":"caolan@caolanmcmahon.com"},"_id":"dispatch@0.2.0","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.101","_nodeVersion":"v0.4.9","_defaultsLoaded":true,"dist":{"shasum":"74ef9fed34bc427d4f0173c17da780fed20c8e4c","tarball":"https://registry.npmjs.org/dispatch/-/dispatch-0.2.0.tgz","integrity":"sha512-yTGUv++oW7Nl2wpst6ALZ1/XSQOOOGNhKLq3duT5gGRlHOIccreAgB4jjkoS08LT5j3qAGtaBVnKI56jl61k5g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBHZ1S+xkM+QLm76tCYgsoxoaxFsyasDqeyRc9k/OrVMAiBtKVm/bkKMfuEWtafthPfQWbw0wBgD7IdAEYO8OIYQsg=="}]},"maintainers":[{"name":"caolan","email":"caolan@caolanmcmahon.com"}],"directories":{}},"1.0.0":{"name":"dispatch","description":"A regular expression URL dispatcher for Connect","main":"./lib/dispatch","author":{"name":"Caolan McMahon"},"version":"1.0.0","repository":{"type":"git","url":"http://github.com/caolan/dispatch.git"},"bugs":{"url":"http://github.com/caolan/dispatch/issues"},"licenses":[{"type":"MIT","url":"http://github.com/caolan/dispatch/raw/master/LICENSE"}],"scripts":{"test":"nodeunit test"},"devDependencies":{"nodeunit":"^0.9.0"},"homepage":"https://github.com/caolan/dispatch","_id":"dispatch@1.0.0","_shasum":"3f5285cb543a5d2d18e097b1c9b7d7f7b15c2bf1","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"caolan","email":"caolan.mcmahon@gmail.com"},"maintainers":[{"name":"caolan","email":"caolan@caolanmcmahon.com"}],"dist":{"shasum":"3f5285cb543a5d2d18e097b1c9b7d7f7b15c2bf1","tarball":"https://registry.npmjs.org/dispatch/-/dispatch-1.0.0.tgz","integrity":"sha512-aCzkGuLekDV2lXugHOJMJxjBIYhWl/sNnB5HTwj3B1xPajFn0XcC8RO/TtA5rZG+cgCQX1Q3nDUFmJa3gyS8jQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDRBtMe4CDhZQG2W+v0SzA5rwZa8D1YMHPbfwdZwVfREgIhAN8y00WflUztu6Nsjyrt1afwmKHV5hNo79VZYFnr3sF2"}]},"directories":{}},"1.0.1":{"name":"dispatch","description":"A regular expression URL dispatcher for Connect","main":"./lib/dispatch","author":{"name":"Caolan McMahon"},"version":"1.0.1","repository":{"type":"git","url":"git+ssh://git@github.com/caolan/dispatch.git"},"bugs":{"url":"http://github.com/caolan/dispatch/issues"},"licenses":[{"type":"MIT","url":"http://github.com/caolan/dispatch/raw/master/LICENSE"}],"scripts":{"test":"nodeunit test"},"devDependencies":{"nodeunit":"^0.9.0"},"gitHead":"4411e886823237cef3cc5b58226dc0fcb413d8cb","homepage":"https://github.com/caolan/dispatch#readme","_id":"dispatch@1.0.1","_shasum":"c257beb14f7431cb14a02ccc1fa9b93c6e4521ea","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"caolan","email":"caolan.mcmahon@gmail.com"},"dist":{"shasum":"c257beb14f7431cb14a02ccc1fa9b93c6e4521ea","tarball":"https://registry.npmjs.org/dispatch/-/dispatch-1.0.1.tgz","integrity":"sha512-H/n4MSZKF7NUdq/ILlMqvhVbwqGCR/5q8fTNRlwOTDexYmnj2GqjRospZoPWa6a66igEJms+SjEdKgsQMX/YEA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCl2+HTkovQfEF0Vknhfp2bqu3DJMO9ghHsnJgac0GK2AIhALxOGBVVLO8PbtKWI/5JCR2PoPjXUpR+xUhzDcDgryXa"}]},"maintainers":[{"name":"caolan","email":"caolan@caolanmcmahon.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/dispatch-1.0.1.tgz_1476776909801_0.66341193462722"},"directories":{}},"1.0.2":{"name":"dispatch","description":"A regular expression URL dispatcher for Connect","main":"./lib/dispatch","author":{"name":"Caolan McMahon"},"version":"1.0.2","repository":{"type":"git","url":"git+ssh://git@github.com/caolan/dispatch.git"},"bugs":{"url":"http://github.com/caolan/dispatch/issues"},"licenses":[{"type":"MIT","url":"http://github.com/caolan/dispatch/raw/master/LICENSE"}],"scripts":{"test":"nodeunit test"},"devDependencies":{"nodeunit":"^0.9.0"},"gitHead":"61cc7043bb71a13b7e5c3db7b66f7bf16f92a783","homepage":"https://github.com/caolan/dispatch#readme","_id":"dispatch@1.0.2","_npmVersion":"5.6.0","_nodeVersion":"8.11.4","_npmUser":{"name":"caolan","email":"caolan.mcmahon@gmail.com"},"dist":{"integrity":"sha512-008aTiwlAjue6/g8oS7jpe3YR9DVibAly6JJ3SGsKzK4wsY0qrCkDNMEf+rqTteOQvF/51+P+79EX+RsBDxPZA==","shasum":"f7748589e1641a1d721770e51970c1c09324e59a","tarball":"https://registry.npmjs.org/dispatch/-/dispatch-1.0.2.tgz","fileCount":5,"unpackedSize":17350,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbl3F8CRA9TVsSAnZWagAAfg0P/AwtQqNLRsmt1ysINMAA\nauSFtC2RvMQyM6l7NoVwFQD60zeOLRfaIn6245XRgRzU/XhSIJx1Ut3I7ste\n0BmniedmGmf4Rf+Fp7AJQByjcVbRgt+o/A9quP/Z+rmYbuI2KxxDBY50Sd4u\nglbUaYl0y/nhxl/E1504qc992AHY1NYCm/Q3hte+Gws3rQ4vOlOofmRJdgN/\nVrZ0bYe3gbmZyDLm2pY0+XwQEWzDXm/AmmkduP4r0r98HjqvvcFXo9o2QCBC\nv6upF0QT4SE8gZrSYNafo3HV8kU12muWH7M5Hjljpr+4mMK3o6k5YlxWw4Yg\np04Q8+KNbgGRiYY2v1TcK6086dIBgZ+o0zZb8YiDOvVe4JRbj4QqBwY9YJXB\nw7cthNmxTScfRcc9+pPBv7PGbOrTpmU3Xwk7l/Q0uuzxzZ1hDH+OBETG4JbF\nIrvPc1mgnu6Rtu4LoKYTf6A6U01T8AFnBaUDZXeNSmnf/fDiL8I059mNicqd\n/aSgx/LZOJYTqAzeR9XmA84/Zktb4MBSvVkLsNAHnCycEZA96IGQlNqmGE3k\n6sa6pnN4RT8n3KxEu1wDcG+l6n9rUpvhkpA1O1r+rTv/7H2XSH7JyVu3Hq9G\n0GWDiVHOvHG6JKfySZWt59ijzKhTBKQPYWqfTWNSc5ZVc3dSEnbI67Z8XFcT\nfSz4\r\n=l9ZR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8Joes6UeCRf4Xg4xzVlVEpQk1Fsfh1eN/HpFGX2Lp4QIhAJal78kfX2p95TirPWfDnNV4nPVxJgTdV+Vcno56XNMG"}]},"maintainers":[{"name":"caolan","email":"caolan@caolanmcmahon.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dispatch_1.0.2_1536651640293_0.7820807717944844"},"_hasShrinkwrap":false}},"maintainers":[{"name":"caolan","email":"caolan@caolanmcmahon.com"}],"author":{"name":"Caolan McMahon"},"repository":{"type":"git","url":"git+ssh://git@github.com/caolan/dispatch.git"},"time":{"0.2.0":"2011-10-29T21:50:10.726Z","modified":"2022-06-15T05:06:40.954Z","created":"2011-10-29T21:50:10.726Z","0.0.1":"2011-10-29T21:50:10.726Z","1.0.0":"2014-05-13T14:07:25.750Z","1.0.1":"2016-10-18T07:48:31.825Z","1.0.2":"2018-09-11T07:40:43.605Z"},"readme":"# Dispatch\n\nA really simple URL dispatcher for\n[Connect](http://github.com/senchalabs/connect) or a plain Node.js HTTP Server.\nAllows arbitrarily nested regular expressions for matching URLs and calling an\nassociated function.\n\n```js\nvar Connect = require('connect'),\n    dispatch = require('dispatch');\n\nConnect.createServer(\n    dispatch({\n        '/about': function(req, res, next){\n            ...\n        },\n        '/user/:id': function(req, res, next, id){\n            ...\n        },\n        '/user/posts': function(req, res, next){\n            ...\n        },\n        '/user/posts/(\\\\w+)': function(req, res, next, post){\n            ...\n        }\n    })\n);\n```\n\nOr, using a vanilla HTTP Server:\n\n```js\nvar http = require('http');\n\nvar server = http.createServer(\n    dispatch({\n        '/about': function(req, res){\n            ...\n        },\n        '/user/:id': function(req, res, id){\n            ...\n        }\n    })\n);\n\nserver.listen(8080);\n```\n\nDispatch can be used with a straight-forward object literal containing view\nfunctions keyed by URL. As you can see from the last URL in the list, captured\ngroups are passed to the matching function as an argument.\n\nYou can also use :named parameters in a URL, which is just a more readable way\nof capturing ([^\\/]+). Named parameters are passed to the matched function in\nthe same way as normal regular expression groups.\n\nSo far so predictable. However, it is also possible to nest these objects as\nyou see fit:\n\n```js\nConnect.createServer(\n    dispatch({\n        '/about': function(req, res, next){ ...  },\n        '/user': {\n            '/': function(req, res, next){ ...  },\n            '/posts': function(req, res, next){ ...  },\n            '/posts/(\\\\w+)': function(req, res, next, post){ ...  }\n        }\n    })\n);\n```\n\nThis helps you tidy up the structure to make it more readable. It also makes\nrenaming higher-level parts of the path much simpler. If we wanted to change\n'user' to 'member', we'd now only have to do that once. Another advantage of\nbeing able to nest groups of URLs is mounting reusable apps in your site tree.\nLet's assume that 'user' is actually provided by another module:\n\n```js\nConnect.createServer(\n    dispatch({\n        '/about': function(req, res, next){ ... },\n        '/user': require('./user').urls\n    })\n);\n```\n\nEasy! A really lightweight and flexible URL dispatcher that just does the\nobvious.\n\nIts also possible to define methods for URLs:\n\n```js\nConnect.createServer(\n    dispatch({\n        '/user': {\n            'GET /item': function(req, res, next){ ... },\n            'POST /item': function(req, res, next){ ... },\n        }\n    })\n);\n```\n\nJust prefix the URL with the http method in uppercase followed by whitespace\nand then the path you want to match against. Nested URLs always match the last\nmethod defined in the tree. Because of this, you can use the following style for\nmatching request methods, if you prefer:\n\n```js\ndispatch({\n    '/test': {\n        GET: function (req, res, next) {\n            ...\n        },\n        POST: function (req, res, next) {\n            ...\n        }\n    }\n})\n```\n\nA couple of implementation points:\n\n1. The regular expressions automatically have '^' and '$' added to the pattern\n   at the start and end or the URL.\n2. Only the first match is called, subsequent matches for a URL will not be\n   called.\n3. If there are no matches, the request is passed to the next handler in the\n   Connect middleware chain.\n\nI like to combine this with [quip](http://github.com/caolan/quip) for rapid\nprototyping and just getting my ideas down in code:\n\n```js\nvar Connect = require('connect'),\n    quip = require('quip'),\n    dispatch = require('dispatch');\n\nvar server = Connect.createServer(\n    quip(),\n    dispatch({\n        '/': function(req, res, next){\n            res.text('hello world!');\n        },\n        '/api': function(req, res, next){\n            res.json({hello: 'world'});\n        }\n    })\n);\n\nserver.listen(8080);\n```\n\nHave fun!\n","readmeFilename":"README.md","homepage":"https://github.com/caolan/dispatch#readme","bugs":{"url":"http://github.com/caolan/dispatch/issues"},"users":{"wits":true,"anlijudavid":true,"andreashae":true}}