{"id":15503043,"url":"https://github.com/johno/router","last_synced_at":"2025-04-22T23:21:15.657Z","repository":{"id":212176445,"uuid":"730819444","full_name":"johno/router","owner":"johno","description":"A miniaturized (and fast af) router for the edge, and everywhere else.","archived":false,"fork":false,"pushed_at":"2023-12-13T14:59:14.000Z","size":90,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-19T17:30:48.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johno.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":".github/contributing.md","funding":".github/funding.yml","license":null,"code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"johno","open_collective":"johno"}},"created_at":"2023-12-12T18:36:55.000Z","updated_at":"2023-12-14T16:51:23.000Z","dependencies_parsed_at":"2025-03-04T16:35:14.586Z","dependency_job_id":"3ee2960f-c62f-4710-8fbe-6bc92f11af44","html_url":"https://github.com/johno/router","commit_stats":null,"previous_names":["johno/router"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johno%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johno","download_url":"https://codeload.github.com/johno/router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250338488,"owners_count":21414196,"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":[],"created_at":"2024-10-02T09:11:56.434Z","updated_at":"2025-04-22T23:21:15.633Z","avatar_url":"https://github.com/johno.png","language":"TypeScript","funding_links":["https://github.com/sponsors/johno","https://opencollective.com/johno"],"categories":[],"sub_categories":[],"readme":"# router\n\nA miniaturized (and fast af) router for the edge, and everywhere else.\n\n```js\nimport { Router, text, json } from \"@johno/router\";\n\nconst router = new Router();\n\nrouter\n  .get(\"/\", (req) =\u003e text(\"Hello world!\"))\n  .get(\"/hello/:name\", (req, env, ctx, routeInfo) =\u003e {\n    json({ name: routeInfo.params.name });\n  });\n\nrouter.handle(request, env, ctx);\n```\n\n## Features\n\n- Simple, declarative API\n- Built for the edge\n- Standards-based (Request/Response/URL)\n- Zero dependencies\n- Tiny footprint\n- ESM-only\n- Written in TypeScript\n\n## Motivation\n\n`@johno/router` is built for edge environments including Cloudflare Workers, Lambda, Netlify Functions, Next.js, etc.\nWhat makes `@johno/router` interesting is what it doesn't do.\n\n**`@johno/router` _does not_:**\n\n- Monkey patch the global `Request` and `Response` objects\n- Route match with regex, it uses a custom parser\n- Implement a bespoke handler API\n- Use middleware, we recommend using lib functions\n- Minify or obfuscate code (readable and debuggable output)\n\n#### Handler API\n\n`@johno/router` uses a simple handler API that is compatible with the [Request][] and [Response][] objects. It _augments_\nedge function handlers with an additional argument, `routeInfo`. This means you can drop in `@johno/router` to any serverless\nfunction environment and you will work with their existing APIs.\n\n## Installation\n\nUse your favorite package manager to install `@johno/router`:\n\n```sh\nnpm install @johno/router\n\n# pnpm add @johno/router\n# yarn add @johno/router\n# bun add @johno/router\n```\n\n## Usage\n\nIf you've used a router before, `@johno/router` will feel familiar.\nTo define a set of routes you:\n\n- Instantiate a router\n- Add routes for given paths and HTTP methods\n- Pass each route a _handler_ function\n- Call `handle` with the request and its environment\n\n```js\nimport { Router, text } from \"@johno/router\";\n\nconst router = new Router();\n\nrouter.get(\"/\", (req, res) =\u003e {\n  text(\"Hello world!\");\n});\n\nrouter.get(\"/hello/:name\", (req, res, routeInfo) =\u003e {\n  text(`Hello ${routeInfo.params.name}!`);\n});\n\nrouter.handle(request, env, ctx);\n```\n\n### Using with Cloudflare Workers\n\n`@johno/router` is designed to work seamlessly with Cloudflare Workers.\nThe `handle` method accepts the `Request`, `Env`, and `Context` objects\nwhich you can leverage in your handlers.\n\n```js\nimport { Router, text, json } from \"@johno/router\";\n\nconst router = new Router();\n\nexport default {\n  async fetch(\n    request: Request,\n    env: Env,\n    ctx: ExecutionContext\n  ): Promise\u003cResponse\u003e {\n    return router\n      .post(\"/hello\", () =\u003e text(\"Hello world!\"))\n      .post(\"/world\", () =\u003e json({ hello: \"world\" }))\n      .handle(request, env, ctx);\n  },\n};\n```\n\n## Code of Conduct\n\nBy participating in our community and interacting with this repository, you agree\nto abide by our [code of conduct](code-of-conduct.md).\n\n## Development\n\nTo learn about how to contribute to this project, please read the [contributing guide](.github/contributing.md).\n\n## License\n\n[MIT](license.md)\n\n---\n\n\u003e Built by [johno](https://johno.com)\n\n[Request]: https://developer.mozilla.org/en-US/docs/Web/API/Request\n[Response]: https://developer.mozilla.org/en-US/docs/Web/API/Response\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohno%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohno%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohno%2Frouter/lists"}