Home > Software engineering >  Naming REST API of user details informations
Naming REST API of user details informations

Time:02-22

Suppose you have 2 relational tables: User and UserDetails. In the user table you store userId, password, email ecc. In the UserDetails table you store other info user-related, such as user preferences, last time logged, last IP ecc. Between User and UserDetails exist a 1-1 relationship, they share the same primary key (userId).

How do you name your REST API to retrieve UserDetails info of a specific user? Is /users/userId/userdetail correct or can you suggest a better API name?

CodePudding user response:

There is no right or wrong way for naming API endpoints. It is best just to be consistent within your application. Since you have two tables with the same id, I might make the endpoint userdetails/{userId} to get the information from the UserDetail table. Then you could have a similar enpoint users/{userId} to get the information from the User table. But again, what you have is perfectly acceptable.

Here is an article that lays some of the best practices for naming API endpoints that I found useful: https://restfulapi.net/resource-naming/

Hopefully that helps!

  •  Tags:  
  • rest
  • Related