What is the proper way for manipulating relationships?


#1

Hi.

Let’s say we have a simple relationships GROUPS to-many USERS

According to documentation, this relationship should be managed using the following url:

/groups/:id_group/users/

I can guest (but I’m not sure and I couldn’t find documentation about it) that if i wish to delete an user from a group I should use an

HTTP DELETE on /groups/:id_group/users/:id_user

Is this true?

But what about adding a new user to the same group? I guest I should use an HTTP PATCH, but what is the right data content? Can some one provide an example?

Thanks in advance, Claudio


#2

Check out this section of the specification and let me know if it’s still unclear. Basically, adding a user to the group will involve a POST to /groups/:id_group/relationships/users, and removing a user from it will involve a DELETE to the same URI (with the id of the user to remove in the body).


#3

Is the “relationships” in the URL required? What does it mean to not include it? What would that be telling the server that is different then including it?


#4

We don’t place any requirements on URLs, those are just examples.


#5

@juicyraoul As @steveklabnik said, /relationships/ is just a convention, not a requirement. The point is that you need to POST to the “relationship URI”, which is identified by the self link in relationship objects, rather than the “related resource URI”, which is identified by the related link. My answer here should help clear things up more if needed.


#6

Hello and thanks for the clarification.
I understand the need to put the ids in the DELETE body when we want to delete more than one user-relationships. but I am wondering, for the case when we want to delete only one relationship, why not DELETE /groups/:id_group/relationships/users/:id_user without a body?
is it simply to have unique way of deletion? or there is another reasons?

regards


#7

I think it was primarily about having only one way to do deletion, to simplify the number of code paths generic clients have to implement.