Best Practices for Naming API Endpoints
1 Use Nouns for Resource Names
Endpoints should represent resources (nouns) rather than actions (verbs). For example, use /users
instead of /getUsers
.
Example:
GET /v1/users
2 Use Plural Names for Collections
When referring to a collection of resources, use plural nouns (e.g., /users
). For a single resource, use the singular form along with its identifier (e.g., /users/{id}
).
Example:
GET /v1/users/{id}
3 Use HTTP Methods to Define Actions
- GET: Retrieve a resource or collection
- POST: Create a new resource
- PUT/PATCH: Update an existing resource
- DELETE: Remove a resource
9 Describe Actions with Query Parameters
Instead of using verbs in your endpoint paths, use query parameters for filtering, sorting, or searching.
Example:
GET /users?status=active
30 December
Tags :
api
,
backend
,
coding
No Comments