{"id":21486246,"url":"https://github.com/ioajs/apip","last_synced_at":"2026-05-05T06:36:13.862Z","repository":{"id":130611398,"uuid":"495094787","full_name":"ioajs/apip","owner":"ioajs","description":"专为 Serverless 环境构建，事件驱动、协议无关的轻量级微型框架","archived":false,"fork":false,"pushed_at":"2022-08-05T12:24:09.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T19:38:50.635Z","etag":null,"topics":["koa","serverless"],"latest_commit_sha":null,"homepage":"","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/ioajs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-22T15:10:06.000Z","updated_at":"2022-08-12T15:29:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"7a232021-757b-4c44-a894-2f0efb53833b","html_url":"https://github.com/ioajs/apip","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioajs%2Fapip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioajs%2Fapip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioajs%2Fapip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioajs%2Fapip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ioajs","download_url":"https://codeload.github.com/ioajs/apip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244014135,"owners_count":20383715,"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":["koa","serverless"],"created_at":"2024-11-23T13:20:05.892Z","updated_at":"2026-05-05T06:36:08.831Z","avatar_url":"https://github.com/ioajs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## apip\r\n\r\n专为 Serverless 环境构建，基于事件的轻量级微型框架，以 Koa Context 作为通用数据交互标准，替换并兼容 Koa.js 中间件生态。\r\n\r\nApip 核心仅包含一个精简的 Koa 洋葱圈模型和基础路由实现，其它功能均为可选，可以按需导入。\r\n\r\n框架刻意设计为单例模式（实际应用中极少会出现在单个进程中创建多个 Koa 实例的场景），当需要创建多个实例时，拆分应用是更好的选择。\r\n\r\n支持多种事件源，不管是 HTTP、RPC、消息队列还是其它，只要遵循 Koa Context 数据结构，即为有效事件，内置可选的 HTTP 事件绑定。\r\n\r\n## Example\r\n\r\n```ts\r\nimport { CTX } from \"apip\";\r\nimport app from \"apip/http\";\r\nimport grpc from \"@apip/grpc\";\r\nimport nats from \"@apip/nats\";\r\nimport cors from \"@koa/cors\";\r\n\r\napp.use(cors({ origin: \"*\" }));\r\n\r\nasync function hello(ctx) {\r\n  ctx.body = \"hello word\";\r\n}\r\n\r\napp.get(\"/\", hello);\r\ngrpc.get(\"/\", hello);\r\nnats.get(\"/\", hello);\r\n\r\napp.post(\"/user\", (ctx) =\u003e {\r\n  ctx.body = \"post\";\r\n});\r\n\r\nnats.post(\"/user\", (ctx) =\u003e {\r\n  ctx.body = \"post\";\r\n});\r\n\r\napp.put(\"/user/:id\", (ctx) =\u003e {\r\n  ctx.body = \"put\";\r\n});\r\n\r\napp.del(\"/user/:id\", (ctx) =\u003e {\r\n  ctx.body = \"delete\";\r\n});\r\n\r\napp.listen(8080);\r\ngrpc.connect();\r\nnats.connect();\r\n\r\nimport { Controller, Get, Post, Put, Del } from \"apip/http\";\r\n\r\n// 装饰器风格的路由\r\n@Controller()\r\nclass Demo {\r\n  @Get(\"/home\")\r\n  home(ctx) {\r\n    ctx.body = { body: \"get\" };\r\n  }\r\n  @Post(\"/home\")\r\n  home(ctx) {\r\n    ctx.body = { body: \"post\" };\r\n  }\r\n  @Put(\"/home\")\r\n  home(ctx) {\r\n    ctx.body = { body: \"put\" };\r\n  }\r\n  @Del(\"/home\")\r\n  home(ctx) {\r\n    ctx.body = { body: \"delete\" };\r\n  }\r\n}\r\n\r\nimport imports from \"apip/imports\";\r\n\r\n// 从指定目录中批量导入多个模块\r\nawait imports(\"./middleware/\");\r\nawait imports(\"./apis/\");\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioajs%2Fapip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fioajs%2Fapip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioajs%2Fapip/lists"}