{"_id":"@apeleghq/routemate","_rev":"1-25905116ce17666c8a6a4e9a0dba5630","name":"@apeleghq/routemate","dist-tags":{"latest":"1.0.7"},"versions":{"1.0.6":{"name":"@apeleghq/routemate","version":"1.0.6","author":{"name":"Apeleg Limited"},"license":"ISC","_id":"@apeleghq/routemate@1.0.6","maintainers":[{"name":"er-ci-bot","email":"npmjs.com+er-ci-bot+fd8b22b478b6fac7@apeleg.com"},{"name":"corrideat","email":"3857362+corrideat@users.noreply.github.com"}],"homepage":"https://github.com/ApelegHQ/routemate#readme","bugs":{"url":"https://github.com/ApelegHQ/routemate/issues"},"dist":{"0":"d","1":"i","2":"s","3":"t","4":"/","5":"i","6":"n","7":"d","8":"e","9":"x","10":".","11":"j","12":"s","shasum":"8a5c7fc4d7506d325836f0a0c937d4857464ab3c","tarball":"https://registry.npmjs.org/@apeleghq/routemate/-/routemate-1.0.6.tgz","fileCount":65,"integrity":"sha512-PsSpB/Kt7hsvXAAyABm/+h3/2wLmoSLfJXR5n4Zi428pT5nGx6cS88s4zeme4fFtPYNAETuHINBaNGn+H6LmDw==","signatures":[{"sig":"MEQCIEs6vPcZpd417t8gkB76Eo2GrttILwAq5HYnuH7JzAi0AiB1scKa/lbdwwLP2VXp7YjeW9w0/Q4zIcHGbDkUCZJAvQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@apeleghq%2froutemate@1.0.6","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":485088},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"deno":{"types":"./dist/index.d.ts","import":"./dist/deno.mjs"},"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js","cloudflare-workers":{"types":"./dist/index.d.ts","import":"./dist/cloudflare-workers.mjs","require":"./dist/cloudflare-workers.mjs"}},"./cloudflare-workers":{"types":"./dist/index.d.ts","import":"./dist/cloudflare-workers.mjs","require":"./dist/cloudflare-workers.mjs"}},"gitHead":"74969bf4155de106fc9eb978883de5c58701cdbe","scripts":{"lint":"eslint . --ext .js,.jsx,.ts,.tsx","test":"node --loader ts-node/esm src/common/router.spec.ts && node --loader ts-node/esm src/listeners/node/index.spec.ts","build":"tsc -b --emitDeclarationOnly --declarationMap --declaration && node esbuild.mjs","prepack":"npm run build","version":"npm run lint && git add -A src","lint:fix":"eslint . --ext .js,.jsx,.ts,.tsx --fix","preversion":"npm run lint","postversion":"git push && git push --tags","prepublishOnly":"npm test && npm run lint"},"_npmUser":{"name":"er-ci-bot","email":"npmjs.com+er-ci-bot+fd8b22b478b6fac7@apeleg.com"},"repository":{"url":"git+https://github.com/ApelegHQ/routemate.git","type":"git"},"_npmVersion":"10.8.2","description":"Routemate is a JavaScript router with support for various environments such as Node.js, Deno and Cloudflare Workers, with more to come.","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"devDependencies":{"eslint":"^8.56.0","esbuild":"^0.23.1","ts-node":"^10.9.2","prettier":"^3.3.3","deno-types":"^1.25.0","typescript":"^5.6.2","@types/node":"^22.5.4","@azure/functions":"^4.5.1","@types/aws-lambda":"^8.10.145","firebase-functions":"^6.0.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@cloudflare/workers-types":"^4.20240909.0","@typescript-eslint/parser":"^8.5.0","@typescript-eslint/eslint-plugin":"^8.5.0"},"peerDependencies":{"firebase-functions":"^6.0.0"},"peerDependenciesMeta":{"firebase-functions":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/routemate_1.0.6_1726072273820_0.03476072193141433","host":"s3://npm-registry-packages"}},"1.0.7":{"name":"@apeleghq/routemate","version":"1.0.7","description":"Routemate is a JavaScript router with support for various environments such as Node.js, Deno and Cloudflare Workers, with more to come.","type":"module","dist":{"0":"d","1":"i","2":"s","3":"t","4":"/","5":"i","6":"n","7":"d","8":"e","9":"x","10":".","11":"c","12":"j","13":"s","integrity":"sha512-GMpFTOkeT0cdHnsn5sPDCtWMrqE/n/JFckYvnIOIq92QAColNwBMiV6nmu7Z9AsXFozdHdjEqnrHcTMwN+hy3Q==","shasum":"9a784d1c52eef0a1e28ce64d6dfccde41a407623","tarball":"https://registry.npmjs.org/@apeleghq/routemate/-/routemate-1.0.7.tgz","fileCount":65,"unpackedSize":485091,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@apeleghq%2froutemate@1.0.7","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC5JmW5cbGEy+CIdJMbneTVnKhbGGPOwMcuun6Q3JLPagIhANAd/QlLujankHcHZPKD+dsAbJlH+kgAxqMW9/TSfap4"}]},"main":"dist/index.cjs","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","deno":{"types":"./dist/index.d.ts","import":"./dist/deno.mjs"},"cloudflare-workers":{"types":"./dist/index.d.ts","import":"./dist/cloudflare-workers.mjs","require":"./dist/cloudflare-workers.cjs"},"import":"./dist/index.mjs","require":"./dist/index.cjs"},"./cloudflare-workers":{"types":"./dist/index.d.ts","import":"./dist/cloudflare-workers.mjs","require":"./dist/cloudflare-workers.cjs"}},"devDependencies":{"@azure/functions":"^4.5.1","@cloudflare/workers-types":"^4.20240909.0","@types/aws-lambda":"^8.10.145","@types/node":"^22.5.4","@typescript-eslint/eslint-plugin":"^8.5.0","@typescript-eslint/parser":"^8.5.0","deno-types":"^1.25.0","esbuild":"^0.23.1","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","firebase-functions":"^6.0.0","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.2"},"peerDependencies":{"firebase-functions":"^6.0.0"},"peerDependenciesMeta":{"firebase-functions":{"optional":true}},"scripts":{"lint":"eslint . --ext .js,.jsx,.ts,.tsx","lint:fix":"eslint . --ext .js,.jsx,.ts,.tsx --fix","build":"tsc -b --emitDeclarationOnly --declarationMap --declaration && node esbuild.mjs","test":"node --loader ts-node/esm src/common/router.spec.ts && node --loader ts-node/esm src/listeners/node/index.spec.ts","prepack":"npm run build","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run lint && git add -A src","postversion":"git push && git push --tags"},"repository":{"type":"git","url":"git+https://github.com/ApelegHQ/routemate.git"},"author":{"name":"Apeleg Limited"},"license":"ISC","_id":"@apeleghq/routemate@1.0.7","gitHead":"dbdaf1d21da5c380c3d0909668cfca1fb988ee68","types":"./dist/index.d.ts","bugs":{"url":"https://github.com/ApelegHQ/routemate/issues"},"homepage":"https://github.com/ApelegHQ/routemate#readme","_nodeVersion":"20.17.0","_npmVersion":"10.8.2","_npmUser":{"name":"er-ci-bot","email":"npmjs.com+er-ci-bot+fd8b22b478b6fac7@apeleg.com"},"directories":{},"maintainers":[{"name":"er-ci-bot","email":"npmjs.com+er-ci-bot+fd8b22b478b6fac7@apeleg.com"},{"name":"corrideat","email":"3857362+corrideat@users.noreply.github.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/routemate_1.0.7_1726177839816_0.7966320867229408"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-11T16:31:13.742Z","modified":"2024-09-12T21:50:40.636Z","1.0.6":"2024-09-11T16:31:14.086Z","1.0.7":"2024-09-12T21:50:40.070Z"},"bugs":{"url":"https://github.com/ApelegHQ/routemate/issues"},"author":{"name":"Apeleg Limited"},"license":"ISC","homepage":"https://github.com/ApelegHQ/routemate#readme","repository":{"type":"git","url":"git+https://github.com/ApelegHQ/routemate.git"},"description":"Routemate is a JavaScript router with support for various environments such as Node.js, Deno and Cloudflare Workers, with more to come.","maintainers":[{"name":"er-ci-bot","email":"npmjs.com+er-ci-bot+fd8b22b478b6fac7@apeleg.com"},{"name":"corrideat","email":"3857362+corrideat@users.noreply.github.com"}],"readme":"# Routemate\n\nRoutemate is a JavaScript router with support for various environments such as Node.js, Deno and Cloudflare Workers, with more to come. It is configured similarly to Express.js but uses standard `Request`, `Response`, and `Headers` elements.\n\n [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_routemate&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_routemate)\n [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_routemate&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_routemate)\n [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_routemate&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_routemate)\n [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_routemate&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_routemate)\n [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_routemate&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_routemate)\n ![NPM Downloads](https://img.shields.io/npm/dw/@apeleghq/routemate?style=flat-square)\n\n## Installation\n\nYou can install Routemate via npm or yarn:\n\n```sh\nnpm install \"@apeleghq/routemate\"\n```\n\n```sh\nyarn add \"@apeleghq/routemate\"\n```\n\n## Getting Started\n\nHere's an example of setting up Routemate for Node.js:\n\n```js\nimport server, { listeners } from '@apeleghq/routemate';\nimport nodeListener from './node';\n// Optional error handler\nimport { handleResponseError } from 'routemate/dist/ResponseError';\n\n// Set up router with Node.js bindings\nconst router = server(listeners.node);\nconst port = 3000;\nconst host = 'localhost';\n\nrouter.get('/', (_req, res) => {\n  const responseBody = 'Hello, World';\n  const headers = { 'content-type': 'text/plain' };\n  return new Response(responseBody, { headers });\n});\n\nrouter['use:error'](handleResponseError);\n```\n\n## API\n\n### `Router`\n\n`Router` is the base router method. It provides several methods to set up routing like `.use` and`.route` (`['use:error']` and `['route:error']` can be used for setting up error handlers). It also provides convenience methods for the standard HTTP methods, like `.get`, `.head`, `.post`, etc.\n\n```js\nimport { Router } from '@apeleghq/routemate';\n\nconst r = Router();\n\n// Request handlers receive three arguments:\n// * req: A Request object with the original request\n// * res: The latest response in the pipeline.\n//        This can be a Response object, `undefined`\n//        for first handler in the pipeline, or it\n//        can be what the last handler returned.\n// * url: A URL object with the request URL for convenience\n// Handlers should return a THandlerResponse, defined as follows:\n// type TResponse = Response | number | null | undefined;\n// Handlers may throw a Response object or a number.\n// This has the effect of returning said response, skipping\n// the remaining handlers in the pipeline.\n\n// Error handlers are also evaluated in a pipeline and receive\n// four arguments\n// * err: The value thrown in a request handler\n// * req: As for request handlers\n// * res: As for request handlers\n// * url: As for request handlers\n\n// Handlers can return a number for an empty response with that\n// status code\nr.get('example/foo', () => 200);\n// Handlers can be async\nr.post('example/foo', () => Promise.resolve(201));\n// A null response is an empty 204 No Content response\nr.put('example/foo', () => null);\n// An undefined response corresponds to 501 Not Implemented\nr.patch('example/foo', () => undefined);\n// .route allows for custom HTTP methods. Methods can be a string\n// or an array\nr.route(['TEST'], 'example/foo', () => 404);\n// Paths can be regular expressions\nr.use(/^example\\/bar$/, () => new Response(null, { status: 599 }));\n\n// Multiple handlers for the same path.\n// They are evaluated *in order*, but the last one is the final\n// response. Handlers receive the previous response as their second\n// argument, so this can be helpful for setting up pipelines\nr.get('example/qux', () => 400);\nr.get('example/qux', () => 202);\n\n// Routers can be nested\nconst child = Router();\nconst grandchild = Router();\n\nchild.get('example/bar', () => 201);\nchild.get('example/baz', grandchild);\ngrandchild.route(undefined, undefined, () => 202);\n```\n\n\n### `server`\n\nThe main entry point for Routemate is the `server`. A `server` is similar to a `Router`, except that it also provides a `listen` method. The `listen` method is used to accept connections.\n\nThe `.listen` method returns a `Promise` that evaluates to a `Router` when successful. It takes three optional arguments, a port number, a hostname and an `AbortSignal` instance. Not all listeners support all arguments. Some listeners may require certain arguments (like a port number) to be given.\n\n```js\nimport server, { listeners } from '@apeleghq/routemate';\n\nconst app = server(listeners.node);\n\n// Optional arguments\nconst port = 3000;\nconst host = 'www.example.com';\nconst abortController = new AbortController();\n\napp.get('/', () => 200);\n\nconst router = await app.listen(port, host, abortController.signal);\n\n// Continue configuration\nrouter.get('/route', () => 200);\n\n// Shut down the server after one second\nsetTimeout(() => abortController.abort(), 1000);\n```\n\n## Roadmap\n\n  * Add support for more environments\n\n## Contributing\n\nContributions are welcome! If you have any ideas for improving this router, please open an issue or submit a pull request.\n\n## License\n\nThis router is licensed under the ISC License. See the `LICENSE` file for details.\n","readmeFilename":"README.md"}