1

Say there are a USER table and a GROUP table in a relational database. As a user can be in many groups and a group can have many users it is Many-to-Many relationship between User and Group.

Now for GET /api/user/userid, should the group field be like

Option 1: [groupid1, groupid2,...]

Option 2: [{id: groupid1, name: groupname,..}, {id: groupid2, name: groupdname,....}]

Option 3: A separate endpoint should be used for group field like GET /api/usergroups/userid

I feel like Option 2 makes more sense for the consumers of the API. But i have seen some big names simply use Option 1. What is your opinion?

Dustin Sun
  • 5,292
  • 9
  • 49
  • 87

0 Answers0