12 Rules to build REST API
1. Use consistent resource naming Plural nouns, kebab-case, no verbs. Your URLs are nouns. HTTP methods are the verbs. `/api/users`, `/api/order-items`, never `/api/getUsers`. 2. Version from day one Put `/v1/` in your base path before you ship. Retrofitting versioning onto a live API is painful. Starting with it is free. 3. Use proper HTTP status codes Not everything is 200. Not every error is 500. 4. Implement pagination from the start Every list endpoint should support `?page=1&limit=20` or cursor-based pagination from day one. Add filtering and sorting through query params (`?status=active&sort=name`). Keeps your API flexible without new endpoints. 5. Use DTOs. Don't leak your DB schema Your database model is not your API response. Shape what goes out. Strip internal IDs, timestamps you don't want exposed, and sensitive fields. 6. Add rate limiting One abusive client shouldn't take down your API. `express-rate-limit` takes five lines. For production, back it w...