-1

I want to design a REST API two resources, users and groups. A user can join multiple groups and a group can have multiple users.

Let's assume you can access related resources via /users/:id/groups and /groups/:id/users. How would you design the enpoints for joining/leaving a group? I could do

POST /users/:id/groups/:id and DELETE /users/:id/groups/:id

but I could also go for

PATCH /users/:id/groups/:id and send a boolean.

Of course I don't need those endpoints for groups because they are redundant, this should be obvious. I'm not sure if this is a opinion based question, but what is the common way to deal with such relationships?

1 Answers1

0

This approach seems to be fine:

POST /users/:id/groups/:id
DELETE /users/:id/groups/:id

The PATCH payload is not supposed to be a boolean value. The PATCH payload is supposed to contain a set of instructions describing how the resource will be modified. Suitable formats are JSON Patch and JSON Merge Patch. Refer to this answer for details.

Community
  • 1
  • 1
cassiomolin
  • 124,154
  • 35
  • 280
  • 359