804 B
804 B
Web 服务器项目
一个简单的 HTTP Web 服务器,提供 RESTful API。
功能特性
- HTTP 服务器
- RESTful API 端点
- JSON 数据处理
- 路由处理
- 中间件支持
- 静态文件服务
API 端点
GET /
- 首页GET /api/users
- 获取用户列表POST /api/users
- 创建新用户GET /api/users/{id}
- 获取特定用户PUT /api/users/{id}
- 更新用户DELETE /api/users/{id}
- 删除用户
运行方法
cd 03-web-server
go run main.go
服务器将在 http://localhost:8080 启动
使用示例
# 获取用户列表
curl http://localhost:8080/api/users
# 创建新用户
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"name":"张三","email":"zhangsan@example.com"}'