{"id":19696257,"url":"https://github.com/axiosleo/node-koapp","last_synced_at":"2025-04-29T11:31:58.711Z","repository":{"id":65358424,"uuid":"517551934","full_name":"AxiosLeo/node-koapp","owner":"AxiosLeo","description":"About Design for quickly developing OpenAPI applications using Node.js","archived":false,"fork":false,"pushed_at":"2025-03-06T02:13:40.000Z","size":176,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T15:11:17.868Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/AxiosLeo.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-25T06:53:28.000Z","updated_at":"2025-03-06T02:13:43.000Z","dependencies_parsed_at":"2024-01-02T08:35:47.104Z","dependency_job_id":"d7f08a1b-152d-48e3-aed3-414da4b44ece","html_url":"https://github.com/AxiosLeo/node-koapp","commit_stats":{"total_commits":55,"total_committers":1,"mean_commits":55.0,"dds":0.0,"last_synced_commit":"d574dad7def8f652079186ebe5725d0c6174e3fc"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxiosLeo%2Fnode-koapp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxiosLeo%2Fnode-koapp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxiosLeo%2Fnode-koapp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxiosLeo%2Fnode-koapp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AxiosLeo","download_url":"https://codeload.github.com/AxiosLeo/node-koapp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251493966,"owners_count":21598205,"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-11-11T19:34:25.862Z","updated_at":"2025-04-29T11:31:58.705Z","avatar_url":"https://github.com/AxiosLeo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @axiosleo/koapp\n\n[![NPM version](https://img.shields.io/npm/v/@axiosleo/koapp.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/koapp)\n[![npm download](https://img.shields.io/npm/dm/@axiosleo/koapp.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/koapp)\n[![CI Build Status](https://github.com/AxiosLeo/node-koapp/actions/workflows/ci.yml/badge.svg)](https://github.com/AxiosLeo/node-koapp/actions/workflows/ci.yml)\n[![](https://codecov.io/gh/AxiosLeo/node-koapp/branch/master/graph/badge.svg)](https://codecov.io/gh/AxiosLeo/node-koapp)\n[![License](https://img.shields.io/github/license/AxiosLeo/node-koapp?color=%234bc524)](LICENSE)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-koapp.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-koapp/refs/branch/master)\n\n\u003e Design for quickly developing Web applications using Node.js\n\u003e\n\u003e Based on [koa](https://koajs.com/)\n\n```bash\nnpm install @axiosleo/koapp\n```\n\n## Initialization\n\n```bash\nnpx @axiosleo/koapp init \u003capp-name\u003e -d \u003coptional-dir\u003e\n\n# show help info\n# npx @axiosleo/koapp init -h\n```\n\n## Quick Start\n\n```javascript\nconst { KoaApplication, Router, success } = require(\"@axiosleo/koapp\");\n\nconst handle = async (ctx) =\u003e {\n  success({\n    message: \"Hello World!\",\n  });\n};\n\nconst router = new Router(\"/test\", {\n  method: \"any\",\n  handlers: [handle],\n});\n\nconst app = new KoaApplication({\n  port: 8088,\n  listen_host: \"localhost\", // 0.0.0.0 for public access\n  routers: [router],\n});\napp.start();\n\n// open http://localhost:8088/test\n```\n\n## More Examples\n\n- Validation\n\n\u003e see [validatorjs](https://github.com/mikeerickson/validatorjs) for more rule examples\n\u003e\n\u003e see `Router` examples for more usage: [tests/bootstrap.js](tests/bootstrap.js)\n\n```javascript\nconst { Router } = require(\"@axiosleo/koapp\");\n\nconst router = new Router(\"/test\", {\n  method: \"any\",\n  validator: {\n    // url params, like `/test/{:id}`, the 'id' is required and must be an integer\n    params: {\n      id: \"required|integer\",\n    },\n    query: {\n      name: \"required|string\",\n    },\n    body: {\n      age: \"required|integer\",\n    }\n  }\n  handlers: [],\n});\n```\n\n- SSE\n\n```javascript\nconst { _foreach, _sleep } = require(\"@axiosleo/cli-tool/src/helper/cmd\");\n\nconst test = async (context) =\u003e {\n  await _foreach([\"0\", \"1\", \"2\", \"3\"], async (item, index) =\u003e {\n    context.koa.sse.send({ data: { item, index } });\n    await _sleep(1000);\n  });\n  context.koa.sse.end();\n};\n\nconst { KoaSSEMiddleware } = require(\"@axiosleo/koapp\");\n\nroot.any(\"/sse\", async (context) =\u003e {\n  const func = KoaSSEMiddleware();\n  await func(context.koa, async () =\u003e {});\n  context.koa.sse.send({ data: \"hello, world!\" });\n  process.nextTick(test, context);\n});\n```\n\n## License\n\nThis project is open-sourced software licensed under [MIT](LICENSE).\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-koapp.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-koapp/refs/branch/master/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxiosleo%2Fnode-koapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxiosleo%2Fnode-koapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxiosleo%2Fnode-koapp/lists"}