Java Api Review
Reviews Java REST API design including HTTP methods, status codes, naming, and versioning. Use when user asks to "review my API", "check REST design", "is this good REST", "review endpoints", "API design review", "check my controller", or "review HTTP API".
Review the REST API design of the provided Java controller or endpoint code. Detect Spring Boot version from pom.xml to tailor advice.
Step 1 — HTTP method and status code correctness
GETmust be idempotent and return200 OK(or404if not found) — never201POSTfor creation → return201 CreatedwithLocationheader pointing to the new resourcePUTfor full replacement →200 OKor204 No ContentPATCHfor partial update →200 OKwith updated resource or204 No ContentDELETE→204 No Content(not200with body)- Flag returning
200 OKwithnullbody when resource not found → must be404 - Flag returning
200 OKfor all errors → each error needs an appropriate 4xx/5xx code
Step 2 — URL naming conventions
- Use plural nouns for resources:
/usersnot/user,/ordersnot/getOrders - Use kebab-case for multi-word paths:
/user-profilesnot/userProfiles - Flag verbs in URLs:
/getUser,/createOrder,/deleteItem→ use HTTP method instead - Nested resources:
/users/{userId}/orders— max 2 levels deep; beyond that use query params - Flag
/api/v1/usersinconsistency — version should be consistent across all endpoints
Step 3 — Request/response design
- Flag endpoints returning raw entity classes (
@Entity) directly → use DTOs - Flag missing
@Validon@RequestBodyparameters → no input validation - Flag
@RequestBody Map<String, Object>→ use typed DTOs instead - Flag missing pagination on list endpoints that could return large datasets → add
Pageable - Flag response bodies that differ in structure between success and error cases → standardize
Step 4 — Error response format
Recommend a consistent error response format:
{
"timestamp": "2024-01-15T10:30:00Z",
"status": 400,
"error": "Validation Failed",
"message": "name must not be blank",
"path": "/api/users"
}
Flag endpoints returning plain strings or stack traces as error responses.
Step 5 — API versioning
- Flag no versioning on public APIs → suggest URL versioning (
/api/v1/) or header versioning - Flag breaking changes in existing versioned endpoints (removing fields, changing types)
Step 6 — Security basics
- Flag endpoints missing
@PreAuthorizeor security config that should be protected - Flag sensitive data (passwords, tokens, SSN) returned in responses
- Flag
@CrossOrigin(origins = "*")on production endpoints
Output format
- Summary — overall API quality assessment
- Issues by severity: 🔴 Critical / 🟡 Warning / 🔵 Suggestion
- Each issue: endpoint + problem + corrected code
Next Steps
- For security findings → ask
java-security-revieweragent for full OWASP review - For missing tests → run
/java-testto generate controller tests with MockMvc