Best Pratices For API Endpoint
Best Pratices For API Endpoint
me
Best
Practices for
Naming API
Endpoints
www.yasirnawaz.me
1
Use Nouns for Resource Names.
GET /v1/users
www.yasirnawaz.me
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}).
GET /v1/users/{id}
www.yasirnawaz.me
3
Use HTTP Methods to Define Actions.
4
Hierarchical Structure
GET /v1/users/{id}/posts
www.yasirnawaz.me
5
Use Consistent Naming Conventions
GET /v1/user-profiles
www.yasirnawaz.me
6
Avoid Special Characters and Spaces
GET /v1/user-profiles
www.yasirnawaz.me
7
Keep It Simple and Intuitive
8
Version Your API
9
Describe Actions with Query
Parameters
1. User Management.
GET /v1/users – Retrieve a list of users.
GET /v1/users/{id} – Retrieve a specific user by
ID.
POST /v1/users – Create a new user.
PUT /v1/users/{id} – Update a user's information.
DELETE /v1/users/{id} – Delete a user.
2. Authentication.
POST /v1/auth/login – User login.
POST /v1/auth/register – User registration.
POST /v1/auth/logout – User logout.
Yasir N.
/in/sudoyasir
www.yasirnawaz.me