{"id":22109762,"url":"https://github.com/iamspark1e/koaw","last_synced_at":"2025-07-20T04:34:15.459Z","repository":{"id":65771683,"uuid":"406481822","full_name":"iamspark1e/koaw","owner":"iamspark1e","description":"Cloudflare Worker version of Koa web application framework, customized, well documented.","archived":false,"fork":false,"pushed_at":"2022-02-18T09:06:37.000Z","size":1407,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-24T17:07:50.158Z","etag":null,"topics":["cloudflare-workers","middleware","serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/iamspark1e.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-09-14T18:37:01.000Z","updated_at":"2022-02-18T09:15:17.000Z","dependencies_parsed_at":"2023-02-09T03:55:11.565Z","dependency_job_id":null,"html_url":"https://github.com/iamspark1e/koaw","commit_stats":null,"previous_names":["arctome/koaw"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamspark1e%2Fkoaw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamspark1e%2Fkoaw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamspark1e%2Fkoaw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamspark1e%2Fkoaw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamspark1e","download_url":"https://codeload.github.com/iamspark1e/koaw/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245206837,"owners_count":20577583,"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","middleware","serverless"],"created_at":"2024-12-01T09:39:04.612Z","updated_at":"2025-03-24T04:17:10.925Z","avatar_url":"https://github.com/iamspark1e.png","language":"JavaScript","readme":"\u003e This project is marked as deprecated since 2025, today I recommend [Hono](https://github.com/honojs/hono), blazing fast and build for edge runtimes.\n\n# Koaw (Deprecated)\n\n[![NPM latest version](https://badgen.net/npm/v/koaw-js)](https://www.npmjs.com/package/koaw-js)\n[![Minified Gzip](https://badgen.net/bundlephobia/minzip/koaw-js)](https://bundlephobia.com/package/koaw-js)\n![Github Action Test](https://github.com/arctome/koaw/actions/workflows/test.yml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/arctome/koaw/badge.svg?branch=main)](https://coveralls.io/github/arctome/koaw?branch=main)\n\nA Koa-like web framework designed for Cloudflare Worker.\n\n\u003e If you are using my old package called `cf-worker-gateway` or `worker-scaffold`, I suggest switching to this package. Using `ctx` is more easily to maintain.\n\n\u003e English is not my native language; please forgive my typing errors. Improvement about documents is also welcomed!\n\n## Installation\n\nInstall the core first,\n\n```bash\nnpm install koaw-js\n# or\nyarn add koaw-js\n```\n\n## Usage\n\n\u003e `Koaw` core and `KoawRouter` all support \"Chaining\".\n\nWithout additional packages, you can use some internal plugins, just like this,\n\n```javascript\nimport Koaw, { KoawRouter, cors } from \"koaw-js\";\n\naddEventListener(\"fetch\", (event) =\u003e {\n  const app = new Koaw(event);\n  const router = new KoawRouter();\n  // KoawRouter's handlers\n  router.get(\"/example\", (ctx) =\u003e {\n    ctx.res.body = \"hello example\";\n    ctx.res.status = 200;\n    ctx.end(); // The `ctx` must call `.end()` to stop middlewares' execution.\n    // If not called at last, the `ctx.res` will be an `unfinished` response.\n  });\n  // Actually inject middlewares in `Koaw` core\n  app.use(cors(true));\n  app.use(router.route());\n\n  event.respondWith(app.run());\n});\n```\n\n## Constructor\n\n```javascript\nconst app = new Koaw(event: FetchEvent, options?: object)\n```\n\nThe `options` accept these configurations,\n\n| Params  | Type      | Description                                                |\n| :------ | :-------- | :--------------------------------------------------------- |\n| `debug` | `boolean` | If set `true`, errors and debug infomation will be printed |\n\n## Plugins (Internal)\n\n### KoawRouter\n\nThe `KoawRouter` is an middleware which manage handlers with path and method.\n\n\u003e The `match` result is generated from package `path-to-regexp`, you can make a more complicate use.\n\n```javascript\nconst router = new KoawRouter();\nrouter.get(\"/a/:id\", (ctx, match) =\u003e {\n  // Router's handler has additional param `match` for dynamic route.\n  ctx.res.body = match.params.id;\n  ctx.res.status = 200;\n  ctx.end();\n});\n// other routes\napp.use(router.route());\n\nevent.respondWith(app.run());\n```\n\n### cors\n\nThe function `cors` is just so simple, you can pass only `true`, and all CORS configuration will work as default. If you want additional config, you can refer [cors in express.js](https://www.npmjs.com/package/cors)\n\n### Transformer\n\n#### `Transformer.responseToCtx`\n\nConvert an exist `Response` to `ctx.res`\n\n```javascript\napp.use(async (ctx) =\u003e {\n  let response = await fetch(\"https://github.com\");\n  ctx.res = await Transformer.responseToCtx(response);\n});\n```\n\n## Plugin Packages\n\n| Package | Description |\n| :------ | :---------- |\n| -       | -           |\n\n## Q \u0026 A\n\n### Q: Why not continuous maintain `@arctome/worker-scaffold` ?\n\nA: The reason is very simple. `WorkerScaffold` is based on `Response` type detection, every step you need construct a new `Response`, which needs a lot of code. Also, construct a `Response` is not an easy way for a Router package, plenty of detection, plenty of clone and re-construction, made the code of core very difficult to maintain. Therefore, I create this package to replace the \"old way\".\n\n\u003e Another reason is that I want to extract the plugins not indispensable. That will allow more plugins developed by community.\n\n### Q: Performance ?\n\nA: Not test for now. Will be added soon.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamspark1e%2Fkoaw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamspark1e%2Fkoaw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamspark1e%2Fkoaw/lists"}