URL Design
- Use nouns, not verbs: /users not /getUsers
- Use plural nouns for collections: /users not /user
- Use hierarchical structure: /users/123/posts
- Keep URLs short and meaningful
- Use lowercase letters and hyphens
- Avoid deep nesting (max 2-3 levels)
HTTP Methods
- GET: Retrieve resources (idempotent, safe)
- POST: Create resources or perform actions
- PUT: Update or replace resources (idempotent)
- PATCH: Partial updates (idempotent)
- DELETE: Remove resources (idempotent)
- Use methods correctly and consistently
Status Codes
- 200 OK: Successful GET, PUT, PATCH
- 201 Created: Successful POST
- 204 No Content: Successful DELETE
- 400 Bad Request: Client error
- 401 Unauthorized: Authentication required
- 403 Forbidden: Insufficient permissions
- 404 Not Found: Resource doesn't exist
- 500 Internal Server Error: Server error
Request & Response Format
- Use JSON for request and response bodies
- Include consistent error response format
- Use pagination for list endpoints
- Include metadata in responses
- Support filtering and sorting
- Version your APIs
Security
- Use HTTPS for all endpoints
- Implement authentication (OAuth 2.0, JWT)
- Use rate limiting to prevent abuse
- Validate and sanitize all inputs
- Implement CORS properly
- Use API keys for third-party access
Documentation
- Document all endpoints with examples
- Include request and response schemas
- Provide code samples
- Keep documentation up to date
- Use OpenAPI/Swagger for interactive docs