allra-api-design
使用 Allra 标准设计 REST API
此技能为 Java Spring Boot 开发者提供标准化的 API 设计指南。它定义了统一的包结构、DTO 命名约定和 REST 端点模式,以确保后端项目的一致性。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“allra-api-design”。 Create a user login API endpoint with email and password validation
预期结果:
- Package structure: user/api/UserController.java, user/dto/request/LoginRequest.java, user/dto/response/LoginResponse.java
- LoginRequest uses Java record with @NotBlank @Email validation on email field
- LoginResponse returns userId and accessToken on successful authentication
- Controller maps POST /api/v1/users/login with proper error handling
正在使用“allra-api-design”。 Design a product management API with CRUD operations
预期结果:
- Domain package: product/ with api, dto, request, response, entity, repository, service layers
- Request DTOs: CreateProductRequest, UpdateProductRequest with validation annotations
- Response DTOs: ProductResponse, ProductListResponse using Java records
- REST endpoints: GET /products, POST /products, PUT /products/{id}, DELETE /products/{id}
安全审计
安全Pure documentation skill containing only API design guidelines. Static scanner produced false positives: 36 'weak cryptographic algorithm' flags are Java 'record' class definitions; 31 'shell backtick execution' flags are markdown code formatting; 5 'system reconnaissance' flags are Spring @PathVariable annotations. No executable code, network access, file system access, or external commands.
风险因素
🌐 网络访问 (1)
⚙️ 外部命令 (31)
质量评分
你能构建什么
新 Spring Boot 项目
从一开始就使用一致的 API 设计模式和包结构启动新的 Spring Boot 项目
团队标准化
在多个开发团队之间建立统一的 API 设计标准以确保一致性
学习 API 最佳实践
通过文档化的指南学习正确的 REST API 设计、DTO 模式和包组织
试试这些提示
按照 Allra API 设计标准为用户注册创建新的 REST API 端点。包括包结构、请求/响应 DTO、控制器和服务层。
按照 Allra 约定为产品管理 API 设计适当的 DTO。包括请求 DTO、响应 DTO 和使用 Java 记录的内部事件 DTO。
审查我当前的 API 包结构,并根据 Allra API 设计标准提出改进建议。检查 DTO 命名、层分离和 REST 约定。
按照 Allra 约定为我的 Spring Boot API 创建标准化的错误响应结构,包括错误代码、消息和详情字段。
最佳实践
- 使用领域驱动的包结构,在 api、dto、entity、repository 和服务之间保持清晰的层分离
- 对简单的 DTO 使用 Java 记录而非类,以减少样板代码
- 应用一致的命名:操作Request、操作Response 和内部操作Dto 后缀
避免
- 在同一类中混合请求和响应 DTO 而非分离它们
- 使用通用名称如 UserDTO 而非特定名称如 UserSignUpRequest
- 跳过请求 DTO 上的 Bean Validation,导致未验证的输入到达服务层