RESTful API Conventions
Core Principles
REST APIs should model systems around resources rather than actions. HTTP verbs define the operations performed on resources.
Resource Naming Standards
-
Use Plural Nouns:
- ✅
/api/orders - ✅
/api/users/42/tokens - ❌
/api/order - ❌
/api/getUser
- ✅
-
No Verbs in URIs:
- HTTP verbs (
GET,POST,PUT,PATCH,DELETE) indicate the action. - ❌
/api/getUsers→ UseGET /api/users - ❌
/api/createOrder→ UsePOST /api/orders - ❌
/api/deleteItem→ UseDELETE /api/items/{id} - Enforced by rule
API-002.
- HTTP verbs (
-
HTTP Status Codes for Responses:
200 OK: Successful read or update201 Created: Resource successfully created (enforced on POST byAPI-003)204 No Content: Successful deletion or operation with no response body400 Bad Request: Client input validation error401 Unauthorized: Authentication missing or invalid403 Forbidden: Authenticated user lacks permission404 Not Found: Resource does not exist500 Internal Server Error: Unhandled server exception (never return 200 for errors, enforced byAPI-001)