Posted 12/05/2024
Endpoints should represent resources, not actions. For example:
/users (to retrieve users)
/getUsers
Use HTTP methods (e.g., GET, POST, PUT, DELETE) to define actions on resources.
Use plural nouns for collections and singular nouns for specific resources:
/users for a collection of users.
/users/{id} for a single user.
Reflect the relationship between resources in the hierarchy:
/users/{id}/orders (orders belonging to a specific user).
Resource names should be lowercase and use hyphens (-) instead of underscores (_) for readability:
/pending-orders
/Pending_Orders or /pending_orders
.Keep URLs flat to avoid complexity. Use query parameters for additional filtering:
/items/{itemId}?userId={userId}
/users/{userId}/orders/{orderId}/items/{itemId}
Specify response formats using headers (Content-Type)
rather than file extensions like .json or .xml
.
Use consistent terminology and patterns across the API to enhance usability. Use Query Parameters for Filtering and Searching
For operations like filtering or sorting, use query parameters:
/users?location=USA&sort=name
.
Include a version, for example in the URI to manage updates gracefully:
/v1/users
.
Choose intuitive, non-abbreviated names:
/users/{id}/profile
/usr/{id}/prf
.