1. Resource Naming Convention

🌐 Use nouns to represent resources (e.g., /users vs /get_users)
✅ Avoid verbs in endpoints; let HTTP methods handle actions
📌 Example:

GET /products/123  
PUT /products/123  
DELETE /products/123
REST_Resource_Naming

2. HTTP Method Standards

🔁 CRUD Operations should map to standard methods:

  • GET for retrieving data
  • POST for creating new resources
  • PUT for updating existing ones
  • DELETE for removing resources

🚫 Never use GET for modifying data

HTTP_Methods

3. Status Code Usage

📊 Use proper status codes for clarity:

  • 200 OK for successful GET/PUT
  • 201 Created for successful POST
  • 404 Not Found for missing resources
  • 400 Bad Request for client errors

🔗 Learn more about HTTP Status Codes

4. Cache Control

⏳ Implement cache headers for performance:

  • Cache-Control: max-age=3600
  • ETag and Last-Modified headers
  • Use 304 Not Modified for cached resources

5. Hypermedia as the Engine of Application State (HATEOAS)

🧭 Include actionable links in responses:

{
  "id": 1,
  "name": "Example Resource",
  "links": [
    {"rel": "self", "href": "/resources/1"},
    {"rel": "edit", "href": "/resources/1/edit"}
  ]
}
HATEOAS_Principle

6. Versioning Strategy

🛠️ Version APIs to ensure backward compatibility:

  • Accept header: application/vnd.myapi.v1+json
  • URL versioning: /api/v1/users
  • Semantic versioning for major/minor updates

📌 See API Versioning Patterns