Search code examples
restjerseyjax-rsrestful-architecture

REST Design: Adding/Deleting a related entity from a given entity using REST


Let's suppose I have an Group of users and I want to add/delete users from the group. What I am confused about is what will be the best practice to design the urls. Here are the options

OPTION # 1

POST /groups/{groupId}/users -- The request body will contain the userId DELETE /groups/{groupId}/users/{userId} -- The userId will be in the path and the request body will be empty

OPTION # 2

DELETE /groups/{groupId}/users -- The request body will contain the userId POST /groups/{groupId}/users/{userId} -- The userId will be in the path and the request body will be empty

I believe both the answers are correct and I am guessing there is no right or wrong answer here, just personal preference.But I would like to know what is used wide-spread. I have been using OPTION # 1 because I read in some book (the name escapes me) that the data you are POSTing shouldn't be a part of the url while using DELETE there is no such best-practice restraint.

All inputs appreciated !


Solution

  • The option 1 seems to be the most common one. I don't have the feeling that the option 2 is valid at all!