REST API Guidelines
Route Design
- APIs MUST be resource-oriented (nouns over verbs).
- Base prefix SHOULD be
/api. - HTTP methods MUST preserve semantics:
GETreadPOSTcreatePUTreplacePATCHpartial updateDELETEremove
Route Conventions
Recommended pattern:
GET /api/<resources>POST /api/<resources>GET /api/<resources>/:idPATCH /api/<resources>/:idDELETE /api/<resources>/:id
Legacy action routes MAY remain for compatibility but SHOULD be phased out.
Request/Response Contracts
- DTOs MUST be defined in
schemas/. - Handlers MUST parse into typed structs, not generic maps.
- Response shape SHOULD stay consistent within a domain.
- Error shape SHOULD include stable status/code/message fields.
Status Codes
200successful read/update201successful create204successful delete with no body400malformed request or validation failure401unauthenticated403unauthorized404not found409conflict410deprecated/removed endpoint429rate/quota limited500unhandled server error
Validation
Validation MUST happen in three layers:
- transport parsing (body, path, query)
- schema validation (required/range/enum)
- business validation in service/model layer
IDs and UUIDs MUST be validated before DB calls.
Pagination
Collection endpoints SHOULD support page and pageSize.
Recommended contract:
- defaults:
page=1, boundedpageSize - response:
items,total,page,pageSize,totalPages
Versioning
Breaking API changes MUST use explicit versioning (/api/v1, /api/v2).