{"id":27979301,"url":"https://github.com/apeleghq/routemate","last_synced_at":"2025-06-19T06:34:50.424Z","repository":{"id":152873809,"uuid":"627144586","full_name":"ApelegHQ/routemate","owner":"ApelegHQ","description":"Simple Multi-Runtime JS Router","archived":false,"fork":false,"pushed_at":"2024-09-12T21:50:05.000Z","size":696,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T08:54:35.944Z","etag":null,"topics":["cloudflare-workers","deno","javascript","nodejs","router","routing","server"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ApelegHQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ApelegHQ"]}},"created_at":"2023-04-12T21:56:47.000Z","updated_at":"2024-09-12T21:49:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"f3fcac47-40c6-4d8a-99ae-2e21fbb53ef9","html_url":"https://github.com/ApelegHQ/routemate","commit_stats":null,"previous_names":["apeleghq/routemate"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/ApelegHQ/routemate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Froutemate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Froutemate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Froutemate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Froutemate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ApelegHQ","download_url":"https://codeload.github.com/ApelegHQ/routemate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Froutemate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260702947,"owners_count":23049372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","deno","javascript","nodejs","router","routing","server"],"created_at":"2025-05-08T02:51:57.838Z","updated_at":"2025-06-19T06:34:45.405Z","avatar_url":"https://github.com/ApelegHQ.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ApelegHQ"],"categories":[],"sub_categories":[],"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\u0026metric=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\u0026metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_routemate)\n [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_routemate\u0026metric=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\u0026metric=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\u0026metric=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) =\u003e {\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', () =\u003e 200);\n// Handlers can be async\nr.post('example/foo', () =\u003e Promise.resolve(201));\n// A null response is an empty 204 No Content response\nr.put('example/foo', () =\u003e null);\n// An undefined response corresponds to 501 Not Implemented\nr.patch('example/foo', () =\u003e undefined);\n// .route allows for custom HTTP methods. Methods can be a string\n// or an array\nr.route(['TEST'], 'example/foo', () =\u003e 404);\n// Paths can be regular expressions\nr.use(/^example\\/bar$/, () =\u003e 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', () =\u003e 400);\nr.get('example/qux', () =\u003e 202);\n\n// Routers can be nested\nconst child = Router();\nconst grandchild = Router();\n\nchild.get('example/bar', () =\u003e 201);\nchild.get('example/baz', grandchild);\ngrandchild.route(undefined, undefined, () =\u003e 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('/', () =\u003e 200);\n\nconst router = await app.listen(port, host, abortController.signal);\n\n// Continue configuration\nrouter.get('/route', () =\u003e 200);\n\n// Shut down the server after one second\nsetTimeout(() =\u003e 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapeleghq%2Froutemate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapeleghq%2Froutemate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapeleghq%2Froutemate/lists"}