Prinsip REST API
REST (Representational State Transfer) adalah arsitektur standar untuk membangun web APIs. Mari pelajari best practices-nya.
Naming Conventions
- Gunakan nouns, bukan verbs:
/usersbukan/getUsers - Gunakan plural:
/postsbukan/post - Gunakan kebab-case:
/user-profiles
HTTP Methods
GET /posts - List all posts
GET /posts/1 - Get single post
POST /posts - Create new post
PUT /posts/1 - Update entire post
PATCH /posts/1 - Partial update
DELETE /posts/1 - Delete post
Status Codes
Gunakan HTTP status codes yang tepat:
- 200 - OK
- 201 - Created
- 400 - Bad Request
- 401 - Unauthorized
- 404 - Not Found
- 500 - Internal Server Error
Pagination
Selalu implementasikan pagination untuk list endpoints.