# What is the proper way for manipulating relationships?

**URL:** <https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123>\
**Category:** Uncategorized\
**Created:** [September 16, 2015, 8:08am UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123 "2015-09-16T08:08:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmelissari](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@cmelissari](https://discuss.jsonapi.org/u/cmelissari)\
**Post date:** [September 16, 2015, 8:08am UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123/1 "2015-09-16T08:08:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)\
**Post date:** [September 16, 2015, 10:21pm UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123/2 "2015-09-16T22:21:34Z")

</div>

Check out [this section](http://jsonapi.org/format/#crud-updating-to-many-relationships) 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).

---

<div class="post-metadata">

**Author:** ![juicyraoul](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/juicyraoul/32/51_2.png) [@juicyraoul](https://discuss.jsonapi.org/u/juicyraoul)\
**Post date:** [October 6, 2015, 1:30pm UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123/3 "2015-10-06T13:30:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![steveklabnik](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/steveklabnik/32/2_2.png) [@steveklabnik](https://discuss.jsonapi.org/u/steveklabnik)\
**Post date:** [October 6, 2015, 2:11pm UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123/4 "2015-10-06T14:11:59Z")

</div>

> [@juicyraoul](#):
>
> Is the “relationships” in the URL required?

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

---

<div class="post-metadata">

**Author:** ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)\
**Post date:** [October 12, 2015, 12:07am UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123/5 "2015-10-12T00:07:08Z")

</div>

@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](http://discuss.jsonapi.org/t/relation-link-usage/149/2) should help clear things up more if needed.

---

<div class="post-metadata">

**Author:** ![malras](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@malras](https://discuss.jsonapi.org/u/malras)\
**Post date:** [March 4, 2016, 9:39pm UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123/6 "2016-03-04T21:39:57Z")

</div>

> [@ethanresnick](#):
>
> removing a user from it will involve a DELETE to the same URI (with the id of the user to remove in the body).

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

---

<div class="post-metadata">

**Author:** ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)\
**Post date:** [March 4, 2016, 10:35pm UTC](https://discuss.jsonapi.org/t/what-is-the-proper-way-for-manipulating-relationships/123/7 "2016-03-04T22:35:13Z")

</div>

> [@malras](#):
>
> 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?

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.
