REST API Naming Conventions and Best Practices
Last Updated: Jan 22, 2025
When designing a REST API, choosing the right naming conventions and best practices is crucial to ensuring maintainability, scalability, and user-friendliness. Proper naming makes the API intuitive and easy to use for developers, reducing cognitive load and improving integration efficiency.
/users
, /orders
Incorrect: /getUsers
, /createOrder
/products
Incorrect: /product
/customer-orders
Incorrect: /customerOrders
/blog-posts
Incorrect: /BlogPosts
Maintain uniformity across all endpoints, e.g., if /employees
is used, avoid /staff
elsewhere.
Example: /user-profile
instead of /user_profile
Example: /order-history
instead of /orderhistorydetails
Good Examples:
/users
(for user management)/orders/123
(fetch order with ID 123)/products?category=electronics
(filtering products by category)/customers/456/orders
(fetch orders for a specific customer)/articles/789/comments
(get comments for a specific article)
Bad Examples:
/getUserDetails
(verb usage instead of noun)/product-listing
(singular form preferred)/api_v1_users
(underscore instead of hyphen)/userDetails-List
(mixed casing and special characters)/store/items?userId=abc
(use path params instead of query params for IDs)
Example: /users/{userId}/orders/{orderId}
Example: Prefer /orders?userId=123
over /users/123/orders/456/items/789
GET /users
)POST /users
)PUT /users/123
)DELETE: Remove a resource (e.g., DELETE /users/123
)
Example: /books/123
Example: /books?author=Mark&sort=asc
500 Internal Server Error: Unexpected server issues
Example: /v1/users
Example: Accept: application/vnd.api.v1+json
Provide meaningful error messages with:
ERR_USER_NOT_FOUND
)User with ID 123 not found
)Suggested actions (e.g., Please check the user ID and try again
)
Following REST API naming conventions and best practices ensures your API is clean, understandable, and easy to use. By adhering to these principles, developers can enhance API performance, maintainability, and adoption.