{"_id":"@bret/http-hash-router","_rev":"4-9f1098d747e144377a5148969ef32ae4","name":"@bret/http-hash-router","description":"Server route handler for http-hash","dist-tags":{"latest":"2.0.0"},"versions":{"1.1.2":{"name":"@bret/http-hash-router","version":"1.1.2","description":"Server route handler for http-hash","keywords":[],"license":"ISC","author":{"name":"Matt Esch","email":"matt@mattesch.info"},"repository":{"type":"git","url":"git://github.com/Matt-Esch/http-hash-router.git"},"dependencies":{"error":"^7.0.2","http-hash":"^2.0.0","http-methods":"^1.0.0","xtend":"^4.0.0"},"devDependencies":{"istanbul":"^0.4.5","opn":"^4.0.2","tape":"^4.6.2","test-server-request":"^2.0.1"},"scripts":{"test":"istanbul cover --print detail --report html test/index.js","view-cover":"opn coverage/index.html"},"main":"index","gitHead":"bcb8ea12b2c19141af3312d9aede23de277b777a","bugs":{"url":"https://github.com/Matt-Esch/http-hash-router/issues"},"homepage":"https://github.com/Matt-Esch/http-hash-router#readme","_id":"@bret/http-hash-router@1.1.2","_shasum":"d5c00f598e8b450331b20cac46bf7cdb3aa9cbd8","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"bret","email":"bcomnes@gmail.com"},"dist":{"shasum":"d5c00f598e8b450331b20cac46bf7cdb3aa9cbd8","tarball":"https://registry.npmjs.org/@bret/http-hash-router/-/http-hash-router-1.1.2.tgz","integrity":"sha512-obGzQLOlZJdLalijoMCpxwgD8LAjdfRytzD1pUl2RRAYmtGOyJ38gJRLIt7WFFXxnD72m2RFfP0QVjr9eJy/7w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFFRIJnS0EzMOrngTqpec6/kSTSf+rF3xzfWD6ionDWiAiEAsN0rTiwZjWxBs0NzAHKeFft3uL/sIxM3UmFCwduHy2Q="}]},"maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/http-hash-router-1.1.2.tgz_1477251824882_0.40600547078065574"}},"2.0.0":{"name":"@bret/http-hash-router","version":"2.0.0","description":"Server route handler for http-hash","keywords":[],"license":"ISC","author":{"name":"Matt Esch","email":"matt@mattesch.info"},"repository":{"type":"git","url":"git://github.com/Matt-Esch/http-hash-router.git"},"dependencies":{"error":"^7.0.2","http-hash":"^2.0.0","http-methods":"^1.0.0","introspect":"0.0.3","xtend":"^4.0.0"},"devDependencies":{"greenkeeper-postpublish":"^1.0.1","istanbul":"^0.4.5","opn":"^4.0.2","tape":"^4.6.2","test-server-request":"^2.0.1"},"scripts":{"test":"istanbul cover --print detail --report html test/index.js","view-cover":"opn coverage/index.html","postpublish":"greenkeeper-postpublish"},"main":"index","gitHead":"bb65364ca57e6d0604a8add93b0ab22a15fde47c","bugs":{"url":"https://github.com/Matt-Esch/http-hash-router/issues"},"homepage":"https://github.com/Matt-Esch/http-hash-router#readme","_id":"@bret/http-hash-router@2.0.0","_shasum":"e7cef47ea126b82628997eb2a142c69b624cd27b","_from":".","_npmVersion":"3.10.8","_nodeVersion":"7.0.0","_npmUser":{"name":"bret","email":"bcomnes@gmail.com"},"dist":{"shasum":"e7cef47ea126b82628997eb2a142c69b624cd27b","tarball":"https://registry.npmjs.org/@bret/http-hash-router/-/http-hash-router-2.0.0.tgz","integrity":"sha512-BqaucLxC64PIJVyi+6+iJxfPEQ1cFANBIW+Gz4D/9wjj5ypf++FTEg3c5PgJAfY7VeG8fPd1Qq2WfhFRuH4CIA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZW1HfIVK2p1ye9G89GRafHZfOY9FzuQv5V49AVcTdGwIgCgOzXU7d5f58eQsacNIta0CwCtPYNRrdbpvH+k5TwnM="}]},"maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/http-hash-router-2.0.0.tgz_1477975819438_0.212435640161857"}}},"readme":"# http-hash-router\n\nServer route handler for http-hash\n\n## Example\n\n```js\nvar http = require('http');\nvar HttpHashRouter = require('http-hash-router');\n\nvar router = HttpHashRouter();\n\nrouter.set('/health', function health(req, res) {\n    res.end('OK');\n});\n\nvar server = http.createServer(function handler(req, res) {\n    router(req, res, {}, onError);\n\n    function onError(err) {\n        if (err) {\n            // use your own custom error serialization.\n            res.statusCode = err.statusCode || 500;\n            res.end(err.message);\n        }\n    }\n});\nserver.listen(3000);\n```\n\n## Documentation\n\n### `var router = HttpHashRouter()`\n\n```ocaml\ntype NotFoundError : Error & {\n    type: \"http-hash-router.not-found\",\n    statusCode: 404\n}\n\ntype Router : {\n    set: (pattern: String, handler: Function | Object) => void\n} & (\n    req: HttpReqest,\n    res: HttpResponse,\n    opts: Object,\n    cb: Callback<NotFoundError | Error, void>\n) => void\n\nhttp-hash-router : () => Router\n```\n\n`HttpHashRouter` will create a new router function.\n\nThe `HttpHashRouter` itself takes no options and returns a\nfunction that takes four arguments, `req`, `res`, `opts`, `cb`.\n\n### `router(req, res, opts, cb)`\n\n```ocaml\ntype NotFoundError : Error & {\n    type: \"http-hash-router.not-found\",\n    statusCode: 404\n}\n\nrouter : (\n    req: HttpReqest,\n    res: HttpResponse,\n    opts: Object,\n    cb: Callback<NotFoundError | Error, void>\n) => void\n```\n\n - throw `http-hash-router.expected.callback` exception.\n\nIt is expected that you call the `router` function with the\n`HTTPRequest` and `HTTPResponse` as the first and second\narguments.\n\nThe third argument is the options object. The `router` will\ncopy the options object and set the `params` and `splat` field.\n\nThe fourth argument is a callback function, this function\neither gets called with a `http-hash-router.not-found` error\nor gets passed to the route handler function.\n\nIf you do not pass a callback to the `router` function then\nit will throw the `http-hash-router.expected-callback` exception.\n\n### `router.set(pattern, handler)`\n\n```ocaml\ntype RoutePattern : String\ntype RouteHandler : Object<method: String, RouteHandler> | (\n    req: HttpRequest,\n    res: HttpResponse,\n    opts: Object & {\n        params: Object<String, String>,\n        splat: String | null\n    },\n    cb: Callback<Error, void>\n) => void\n\nset : (RoutePattern, RouteHandler) => void\n```\n\nYou can call `.set()` on the router and it will internally\nstore your handler against the pattern.\n\n`.set()` takes a route pattern and a route handler. A route\n    handler is either a function or an object. If you use\n    an object then we will create a route handler function\n    using the [`http-methods`][http-methods] module.\n\nThe `.set()` functionality is implemented by\n[`http-hash`][http-hash] itself and you can find documentation\nfor it at [HttpHash#set][http-hash-set].\n\nYour handler function will get called with four arguments.\n\n - `req` the http request stream\n - `res` the http response stream\n - `opts` options object. This contains properties defined\n    in the server and also contains the `params` and `splat`\n    fields.\n - `cb` callback.\n\nIf your route pattern contains a param, i.e. `\"/foo/:bar\"` or\nyour route pattern contains a splat, i.e. `\"/foo/*\"` then \nthe values of the params and splat will be passed to the\n`params` and `splat` field on `opts`.\n\n  [http-hash]: https://github.com/Matt-Esch/http-hash\n  [http-hash-set]: https://github.com/Matt-Esch/http-hash#hashsetpath-handler\n  [http-methods]: https://github.com/Raynos/http-methods\n","maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"time":{"modified":"2022-06-12T15:29:02.363Z","created":"2016-10-23T19:43:45.122Z","1.1.2":"2016-10-23T19:43:45.122Z","2.0.0":"2016-11-01T04:50:21.171Z"},"homepage":"https://github.com/Matt-Esch/http-hash-router#readme","keywords":[],"repository":{"type":"git","url":"git://github.com/Matt-Esch/http-hash-router.git"},"author":{"name":"Matt Esch","email":"matt@mattesch.info"},"bugs":{"url":"https://github.com/Matt-Esch/http-hash-router/issues"},"license":"ISC","readmeFilename":"Readme.md"}