{"id":15365690,"url":"https://github.com/tunnckocore/urlpattern-router","last_synced_at":"2025-04-15T09:53:12.072Z","repository":{"id":60918086,"uuid":"546678862","full_name":"tunnckoCore/urlpattern-router","owner":"tunnckoCore","description":"An isomorphic router based on URLPattern Web spec in 180 lines (including 60 lines of types, 40 lines of comments). Works for @denoland, Bun, @nodejs, @cloudflare, Browsers, or anything that has support for URLPattern.","archived":false,"fork":false,"pushed_at":"2023-06-09T18:17:17.000Z","size":8509,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T07:42:56.360Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://developer.mozilla.org/en-US/docs/Web/API/URLPattern","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tunnckoCore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-06T13:21:01.000Z","updated_at":"2025-01-18T01:49:09.000Z","dependencies_parsed_at":"2023-02-18T18:16:19.334Z","dependency_job_id":null,"html_url":"https://github.com/tunnckoCore/urlpattern-router","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Furlpattern-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Furlpattern-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Furlpattern-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Furlpattern-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tunnckoCore","download_url":"https://codeload.github.com/tunnckoCore/urlpattern-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249048713,"owners_count":21204306,"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-01T13:15:34.634Z","updated_at":"2025-04-15T09:53:12.053Z","avatar_url":"https://github.com/tunnckoCore.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# urlpattern-router\n\n\u003e Router based on [URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) Web Specification, _in 150 lines_ and used in Production!\n\n\u003e An **isomorphic router** for **@denoland**, **@nodejs** (probably), **@cloudflare**, Browsers, or anything that has support for it!\n\nSee the examples. Briefly, the basic stuff of a router, LOL.\n\n**Note:** You can also somehow import [urlpattern-polyfill](https://unpkg.com/urlpattern-polyfill) for environments that don't have it yet - Deno, Deno Deploy, and Cloudflare does.\n\n```js\n// Cloudflare or others\nimport { Router, json, ok, notFound } from \"urlpattern-router\";\n\n// Or Deno: `https://ghuc.cc/tunnckoCore/urlpattern-router/index.js`\n// import { Router, json, ok, notFound } from \"urlpattern-router\";\n\nconst router = new Router({ baseURL: \"http://some-domain.com\" });\n\nrouter\n\t.get(\"/\", async () =\u003e new Response(\"Homepage hehe!\"))\n\t.get(\"/item/:id\", (req, { params }) =\u003e ok(`Matching id: ${params.id}`))\n\t.get(\"/api/hello\", () =\u003e json({ hello: \"world\" }))\n\t.get(\"/api/hi/:name\", (req, { params: { name } }) =\u003e json({ hi: name }));\n\n// or router._routes\nconsole.log(router);\n```\n\n### by request method\n\n- router.all\n- router.any\n- router.get\n- router.post\n- router.put\n- router.patch\n- router.delete\n- router.head\n- router.options\n\n### handling\n\n- router.addRoute - used internally for above methods\n- router.match\n- router.matchRequest\n- router.handle - calls the handler for matching route\n- router.fetch - useful for Cloudflare Workers\n- router.clear - clear routes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunnckocore%2Furlpattern-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftunnckocore%2Furlpattern-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunnckocore%2Furlpattern-router/lists"}