首页/ AI 技能 / @skilllib/skill-2014279404120125441
Skill站外收录 @skilllib/skill-2014279404120125441

api-design

指导构建符合行业标准的 RESTful API,强调以资源为中心的设计理念,合理运用 HTTP 方法语义,采用清晰的 URL 结构与 JSON 响应格式,统一错误处理机制和状态码规范,并涵盖版本控制、分页、限流及 OpenAPI 文档化等工程实践。

0.0 (0) 199 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# API Design Skill This skill provides comprehensive guidance for designing RESTful APIs following industry best practices. ## Core Principles ### 1. Resource-Oriented Design - Use nouns for resource names (e.g., `/users`, `/products`) - Avoid verbs in URLs - Use HTTP methods to represent actions ### 2. HTTP Methods - **GET**: Retrieve resources - **POST**: Create new resources - **PUT**: Update entire resources - **PATCH**: Partial updates - **DELETE**: Remove resources ### 3. URL Structure ``` GET /api/v1/users - List all users GET /api/v1/users/{id} - Get specific user POST /api/v1/users - Create new user PUT /api/v1/users/{id} - Update user DELETE /api/v1/users/{id} - Delete user ``` ### 4. Response Format - Use JSON as default format - Use camelCase for field names - Include metadata (pagination, timestamps) ### 5. Error Handling ```json { "error": { "code": "INVALID_REQUEST", "message": "User ID must be a positive integer", "details": [] } } ``` ### 6. Status Codes - 200: Success - 201: Created - 400: Bad Request - 401: Unauthorized - 404: Not Found - 500: Internal Server Error ## Best Practices - Version your APIs - Use pagination for list endpoints - Implement rate limiting - Document with OpenAPI/Swagger

评论 0

还没有评论,来抢沙发。