# whyb **Repository Path**: lmsorry/whyb ## Basic Information - **Project Name**: whyb - **Description**: cangjie web framework,仓颉web框架 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-12 - **Last Updated**: 2026-02-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # WhyB - 仓颉Web框架 一个用仓颉(Cangjie)语言编写的简单Web框架。 ## 特性 - 🚀 简单易用的API - 🔄 支持多种HTTP方法(GET, POST, PUT, DELETE, PATCH, OPTIONS) - 🛣️ 灵活的路由系统 - 🔌 中间件支持 - 📝 请求/响应处理 - 🌐 并发请求处理 ## 项目结构 ``` whyb/ ├── src/ │ ├── http/ │ │ ├── request.cj # HTTP请求类 │ │ ├── response.cj # HTTP响应类 │ │ └── server.cj # HTTP服务器 │ ├── router/ │ │ └── router.cj # 路由系统 │ ├── whyb.cj # 框架主类 │ └── main.cj # 示例应用 ├── cjpm.toml # 项目配置 └── README.md # 说明文档 ``` ## 快速开始 ### 创建应用 ```cangjie import whyb import whyb.http.Request import whyb.http.Response main() { let app = WhyB.create(8080) app.get("/", { req => Response.ok("Hello, World!") }) app.listen() } ``` ### 路由 ```cangjie // GET请求 app.get("/hello", { req => Response.ok("Hello!") }) // POST请求 app.post("/api/data", { req => Response.ok("Created") }) // PUT请求 app.put("/api/users/:id", { req => Response.ok("Updated") }) // DELETE请求 app.delete("/api/users/:id", { req => Response.ok("Deleted") }) ``` ### 中间件 ```cangjie app.use({ req, next => println("[LOG] ${req.method} ${req.getPath()}") let response = next(req) response }) ``` ### 运行 ```bash cjpm run ``` 服务器将在 http://localhost:8080 启动 ## API端点 示例应用包含以下端点: - `GET /` - 首页 - `GET /hello` - 问候页面 - `GET /api/data` - JSON数据 - `GET /api/users` - 用户列表 - `POST /api/echo` - 回显POST数据 ## 测试 ```bash # 测试首页 curl http://localhost:8080/ # 测试JSON API curl http://localhost:8080/api/data # 测试POST请求 curl -X POST http://localhost:8080/api/echo -d "Hello" ``` ## 许可证 MIT License