This skill provides RESTful API design guidance to ensure consistent endpoints, clear responses, and scalable documentation across services.
npx playbooks add skill enoch-robinson/agent-skill-collection --skill api-design
提供专业的 RESTful API 设计指导,确保接口一致性、可用性和可扩展性。
GET /users# 获取用户列表
GET /users/{id} # 获取单个用户
POST /users # 创建用户
PUT /users/{id} # 更新用户(全量)
PATCH /users/{id} # 更新用户(部分)
DELETE /users/{id} # 删除用户
/users 而非 /user/user-profiles 而非 /userProfilesPOST /users 而非 /createUser/users/{id}/orders(最多 2 层)| 状态码 | 含义 | 使用场景 |
|--------|------|----------|
| 200 | OK | GET/PUT/PATCH 成功 |
| 201 | Created | POST 创建成功 |
| 204 | No Content | DELETE 成功 |
| 400 | Bad Request | 请求参数错误 |
| 401 | Unauthorized | 未认证 |
| 403 | Forbidden | 无权限 |
| 404 | Not Found | 资源不存在 |
| 422 | Unprocessable | 业务验证失败 |
| 500 | Server Error | 服务器错误 |
{
"data": {
"id": "123",
"name": "张三",
"email": "zhang@example.com"
},
"meta": {
"timestamp": "2024-01-15T10:30:00Z"
}
}
{
"data": [...],
"pagination": {
"page": 1,
"per_page": 20,
"total": 100,
"total_pages": 5
}
}
{
"error": {
"code": "VALIDATION_ERROR",
"message": "请求参数验证失败",
"details": [
{"field": "email", "message": "邮箱格式不正确"}
]
}
}
推荐 URL 路径版本:
/api/v1/users
/api/v2/users
# 分页
?page=1&per_page=20
# 排序
?sort=created_at&order=desc
# 过滤
?status=active&role=admin
# 字段选择
?fields=id,name,email
# 搜索
?q=keyword
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.