Tips and How to name you API endpoint?

Sometimes, it can be very confusing on how to name your api endpoint.

This is the tips and guideline for you on how to name your API endpoint

1. Use only nouns, rather than adding verbs

Example:

๐Ÿ‘๐Ÿป /users
๐Ÿ‘Ž๐Ÿป /get-users

It will be funny…


This content originally appeared on DEV Community and was authored by Muhammad Harith Zainudin

Sometimes, it can be very confusing on how to name your api endpoint.

This is the tips and guideline for you on how to name your API endpoint

1. Use only nouns, rather than adding verbs

Example:

๐Ÿ‘๐Ÿป /users
๐Ÿ‘Ž๐Ÿป /get-users

It will be funny if you put action in the endpoint. We will directly straight know, it use a GET request.
Use singular or plural nouns? It depends.
If get more user, preferably use /users. If one user, then /user is the answer

2. Short, Clear and Intuitive

Example:

๐Ÿ‘๐Ÿป /id
๐Ÿ‘Ž๐Ÿป /identification-number
๐Ÿ‘Ž๐Ÿป /id/1234/fn

For example 3, this would be misleading. It's not clear. What is fn? As for me, I would think it a function

3. Build hierarchy and grouping into logical groups

Example:

๐Ÿ‘๐Ÿป /departments/managers
๐Ÿ‘๐Ÿป /product/variation

4. Use only lowercase

Example:

๐Ÿ‘๐Ÿป /kyc-form-application
๐Ÿ‘Ž๐Ÿป /KYCFormApplication

URIs are case sensitive, try to avoid upper case unless it is necessary. And also, avoid unnecessary confusion and inconsistency in naming your endpoint.

5. Avoid special characters in the endpoint

Example:

๐Ÿ‘๐Ÿป /store
๐Ÿ‘Ž๐Ÿป /%store

You can refer here for list of special character

6. Use hyphen (-) to separate words rather than underscore (_) or camelCase

Example:

๐Ÿ‘๐Ÿป /generate-s3-presigned-url
๐Ÿ‘Ž๐Ÿป /generateS3PresignedUrl

Your endpoint will looks more cleaner, clearer and user friendly. Google recommend us to use hyphens as it is good for Google search, it make its web crawling job easier, thus creating more consistent results.

7. Use camelCase for parameters

Example:

๐Ÿ‘๐Ÿป /user/{userId}
๐Ÿ‘Ž๐Ÿป /user/{user_id}

8. Do versioning for your user to use the endpoint

Example:
Ways to do versioning in your API endpoint

Our API will keep changing over the time, the implementation, the request body, the response etc, hence versioning is important to avoid the endpoint from breaking when the user use it. For me, the easiest way to do versioning is the 1st way.

Avoid doing silly mistake like me when I create my endpoint before this. But hey, we learn from our mistakes right?
Silly mistake by me

That's all for the tips and how to naming your endpoint!

Thank you for reading :D

Psstt pstt :p
Do consider to love this article โค๏ธ and follow me! Why not right? It's FREE~
I would really appreciate it ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป
Will be posting more on things related to AWS, Javascript, Python, Serverless and more!


This content originally appeared on DEV Community and was authored by Muhammad Harith Zainudin


Print Share Comment Cite Upload Translate Updates
APA

Muhammad Harith Zainudin | Sciencx (2022-04-10T01:21:02+00:00) Tips and How to name you API endpoint?. Retrieved from https://www.scien.cx/2022/04/10/tips-and-how-to-name-you-api-endpoint/

MLA
" » Tips and How to name you API endpoint?." Muhammad Harith Zainudin | Sciencx - Sunday April 10, 2022, https://www.scien.cx/2022/04/10/tips-and-how-to-name-you-api-endpoint/
HARVARD
Muhammad Harith Zainudin | Sciencx Sunday April 10, 2022 » Tips and How to name you API endpoint?., viewed ,<https://www.scien.cx/2022/04/10/tips-and-how-to-name-you-api-endpoint/>
VANCOUVER
Muhammad Harith Zainudin | Sciencx - » Tips and How to name you API endpoint?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/10/tips-and-how-to-name-you-api-endpoint/
CHICAGO
" » Tips and How to name you API endpoint?." Muhammad Harith Zainudin | Sciencx - Accessed . https://www.scien.cx/2022/04/10/tips-and-how-to-name-you-api-endpoint/
IEEE
" » Tips and How to name you API endpoint?." Muhammad Harith Zainudin | Sciencx [Online]. Available: https://www.scien.cx/2022/04/10/tips-and-how-to-name-you-api-endpoint/. [Accessed: ]
rf:citation
» Tips and How to name you API endpoint? | Muhammad Harith Zainudin | Sciencx | https://www.scien.cx/2022/04/10/tips-and-how-to-name-you-api-endpoint/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.