Loading lessons...
RESTful API Architecture Principles
Designing Clean REST APIs
REST (Representational State Transfer) is an architectural style for designing networked applications using stateless communications and HTTP standard verbs.
Key Rules of RESTful API Design
- Nouns over Verbs for Endpoints: Use plural resource nouns instead of action verbs.
- Good:
GET /api/v1/users - Bad:
GET /api/v1/getUsersorPOST /api/v1/deleteUser
- Stateless Requests: Every request must contain all information required to fulfill it (e.g. JWT Auth headers).
- Standard HTTP Verbs:
GET: Fetch resource(s) (Safe & Idempotent).POST: Create a resource (Non-idempotent).PUT: Replace a resource entirely (Idempotent).PATCH: Partial update of resource (Non-idempotent).DELETE: Delete a resource (Idempotent).
- Hierarchical Nested Resources:
GET /api/v1/users/42/posts(Fetches posts belonging to user 42).
TL;DR
- Use plural nouns for resource paths (
/api/v1/products). - Rely on HTTP methods (
GET,POST,PUT,DELETE) to specify operations rather than URL verbs.