REST API 文档
GoCode Monorepo 提供统一的 RESTful API 接口。
基础信息
- Base URL:
http://localhost:8080/api/v1 - 认证方式: JWT Bearer Token
- 数据格式: JSON
认证
获取访问令牌
POST /api/v1/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "your-password"
}响应:
{
"code": 200,
"message": "success",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"name": "John Doe",
"email": "user@example.com"
}
}
}使用令牌
在后续请求的 Header 中添加:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...用户 API
获取用户列表
GET /api/v1/users
Authorization: Bearer {token}响应:
{
"code": 200,
"message": "success",
"data": {
"items": [
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}
],
"total": 100,
"page": 1,
"pageSize": 20
}
}创建用户
POST /api/v1/users
Authorization: Bearer {token}
Content-Type: application/json
{
"name": "Jane Doe",
"email": "jane@example.com",
"password": "secure-password"
}错误处理
所有错误响应遵循统一格式:
{
"code": 400,
"message": "Invalid request",
"error": "Email is required"
}常见状态码
200 OK: 请求成功201 Created: 创建成功400 Bad Request: 请求参数错误401 Unauthorized: 未授权403 Forbidden: 禁止访问404 Not Found: 资源不存在500 Internal Server Error: 服务器错误
