{"id":23892675,"url":"https://github.com/tenapato/cfw-ts-apiserver-template","last_synced_at":"2026-05-15T11:34:10.299Z","repository":{"id":59116050,"uuid":"535475103","full_name":"tenapato/cfw-ts-apiserver-template","owner":"tenapato","description":"Cloudflare workers TS api boilerplate using subrouting","archived":false,"fork":false,"pushed_at":"2023-03-14T16:51:55.000Z","size":117,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T05:43:47.571Z","etag":null,"topics":["api","boilerplate","cloudflare","cloudflare-workers","rest","rest-api","router","routing","subrouting","template","templates","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tenapato.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":null,"support":null}},"created_at":"2022-09-12T01:38:30.000Z","updated_at":"2023-03-14T16:52:22.000Z","dependencies_parsed_at":"2022-09-12T15:04:09.604Z","dependency_job_id":null,"html_url":"https://github.com/tenapato/cfw-ts-apiserver-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tenapato/cfw-ts-apiserver-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenapato%2Fcfw-ts-apiserver-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenapato%2Fcfw-ts-apiserver-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenapato%2Fcfw-ts-apiserver-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenapato%2Fcfw-ts-apiserver-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tenapato","download_url":"https://codeload.github.com/tenapato/cfw-ts-apiserver-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenapato%2Fcfw-ts-apiserver-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33065488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","boilerplate","cloudflare","cloudflare-workers","rest","rest-api","router","routing","subrouting","template","templates","typescript"],"created_at":"2025-01-04T13:59:39.769Z","updated_at":"2026-05-15T11:34:10.270Z","avatar_url":"https://github.com/tenapato.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CloudFlare Workers Typescript REST API Boilerplate\n\u003e Author: Patricio Tena\n\nThis is a REST API boilerplate for CloudFlare Workers using Typescript. This template uses subrouting to give a better organization for each hanlder and its respective functions.\n\n## Parent Router\nFirst you create a `parent` router as follows:\n```ts\nconst parent = Router()\n\nparent\n  .all('/v1/handler*', handlerRoutes.handle)\n  .all('*', () =\u003e missing('Root API could not find that endpoint.'))\n```\n\nAs you can see in the example above, the parent router has a handler for each hanlder subrouter. \nI personally create each subrouter routes in the `/routes` folder, then export it to the `handler.ts`.\n\n\n## Child Routers\n\nEach child router must have a base defined:\n\n```ts\nconst v1 = Router({ base: '/v1' }) \n```\n\nAfter that you can use it as a regular router:\n```ts\nimport {handleFetch} from '../handlers/handler'\nv1\n  .get('/handler/test', () =\u003e new Response(\"Testing!\", { status: 200 }))\n  .get('/handler',handleFetch)\n  .all('*', () =\u003e missing('API v1/handler could not find that endpoint.'))\n\nexport default v1\n```\n\u003e The handleFecth function is imported from the `./handlers` folder. \n\n## Handlers\n\nA basic structure for a function hanlder can look something like this:\n\n```ts\nexport async function handleFetch(event: Event){\n    try{\n        return new Response(JSON.stringify({\n            status: 200,\n            message: 'Ok',}), {\n        status: 200,\n        headers: {\n            'Access-Control-Allow-Origin': '*',\n            'Content-Type': 'application/json'\n        }\n        })\n    }catch(err){\n        console.log(err);\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenapato%2Fcfw-ts-apiserver-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftenapato%2Fcfw-ts-apiserver-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenapato%2Fcfw-ts-apiserver-template/lists"}