0% found this document useful (0 votes)
35 views12 pages

Best Pratices For API Endpoint

Uploaded by

Daniel Bdkmv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views12 pages

Best Pratices For API Endpoint

Uploaded by

Daniel Bdkmv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

www.yasirnawaz.

me

Best
Practices for
Naming API
Endpoints
www.yasirnawaz.me

1
Use Nouns for Resource Names.

Endpoints should represent resources (nouns)


rather than actions (verbs).
For example, use /users instead of /getUsers.

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.

GET. Retrieve a resource or a collection of resources


(e.g., GET /users, GET /users/{id}).

POST. Create a new resource (e.g., POST /users).

PUT or PATCH. Update an existing resource (e.g.,


PUT /users/{id} or PATCH /users/{id}).

DELETE. Remove a resource (e.g., DELETE


/users/{id}).
www.yasirnawaz.me

4
Hierarchical Structure

Use a clear and logical hierarchy to represent


relationships between resources (e.g.,
/users/{id}/posts to represent posts by a specific
user).

GET /v1/users/{id}/posts
www.yasirnawaz.me

5
Use Consistent Naming Conventions

Stick to a consistent naming convention, such as


snake_case or kebab-case, and be consistent
throughout your API (e.g., /user_profiles or /user-
profiles).

GET /v1/user-profiles
www.yasirnawaz.me

6
Avoid Special Characters and Spaces

Use hyphens (-) to separate words instead of spaces


or underscores in URL paths (e.g., /user-profiles
rather than /user_profiles).

GET /v1/user-profiles
www.yasirnawaz.me

7
Keep It Simple and Intuitive

Names should be easy to understand and


remember. Avoid complex or overly technical
terminology.
www.yasirnawaz.me

8
Version Your API

Include versioning in your endpoint paths to allow


for future changes without breaking existing clients
(e.g., /v1/users).
www.yasirnawaz.me

9
Describe Actions with Query
Parameters

Instead of using verbs in your endpoint paths, use


query parameters for filtering, sorting, or searching
(e.g., GET /users?status=active).
www.yasirnawaz.me

Examples of Well-Named API Endpoints

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

You might also like