| name | api-conventions |
| description | Use when writing or reviewing REST controllers, HTTP endpoints, URL paths, route naming, HTTP verbs, status codes in a Spring Boot project |
API Conventions — REST
Three rules covering HTTP verbs, URL structure, and status codes.
All three are feedforward rules — AI code review references their IDs in PR comments.
Rules
API-001 — Use correct HTTP verbs
Match the verb to the intent. Never use GET for mutations.
| Verb | Use for |
|---|
GET | Read — must be safe and idempotent, no side effects |
POST | Create a new resource |
PUT | Full replace of an existing resource |
PATCH | Partial update of an existing resource |
DELETE | Remove a resource |
@GetMapping("/users/{id}/deactivate")
@PostMapping("/users/{id}/deactivation")
API-002 — No verbs in URL paths
URLs identify resources (nouns), not actions (verbs). Use plural nouns.
// ❌ API-002 violations
GET /getUser/42
POST /createOrder
GET /users/42/doDeactivate
// ✅ correct
GET /users/42
POST /orders
DELETE /users/42/activation
Sub-resources are fine: /users/{id}/orders reads as "orders belonging to user".
API-003 — Return correct HTTP status codes
return ResponseEntity.ok(createdUser);
return ResponseEntity.ok().build();
return ResponseEntity
.created(URI.create("/users/" + user.getId()))
.body(user);
return ResponseEntity.noContent().build();
Rule of thumb: if the response body is empty, use 204. If a resource was just created, use 201 with a Location header.
Quick reference
| ID | Rule | Enforced by |
|---|
API-001 | Correct HTTP verb for the intent | AI code review (PR) |
API-002 | No verbs in URL paths, plural nouns | AI code review (PR) |
API-003 | Correct status codes (201/204/400/404/409) | AI code review (PR) |