# Body of sucessful relationship update response

**URL:** <https://discuss.jsonapi.org/t/body-of-sucessful-relationship-update-response/1370>\
**Category:** Uncategorized\
**Created:** [September 1, 2018, 1:26pm UTC](https://discuss.jsonapi.org/t/body-of-sucessful-relationship-update-response/1370 "2018-09-01T13:26:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![a-komarev](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/a-komarev/32/440_2.png) [@a-komarev](https://discuss.jsonapi.org/u/a-komarev)\
**Post date:** [September 1, 2018, 1:26pm UTC](https://discuss.jsonapi.org/t/body-of-sucessful-relationship-update-response/1370/1 "2018-09-01T13:26:58Z")

</div>

Documentation section [Updating Relationships](http://jsonapi.org/format/#crud-updating-relationship-responses-200) says:

> The response document **MUST** include a representation of the updated relationship(s).

Resource `Team` can has many `members` of `User` type.

```json
{
  data: {
    type: "Team",
    id: "team-1",
    relationships: {
      members: {
        data: [
          {
            type: "User",
            id: "user-1"
          }
        ]
      }
    }
  }
}

```

If we want to update members list we could make PATCH request on relationship.

`PATCH /teams/team-1/relationships/members`

```json
{
  data: [
    {
      type: "User",
      id: "user-1"
    },
    {
      type: "User",
      id: "user-2"
    },
  ]
}

```

What response client should expect?

1. Same as request:

```json
{
  data: [
    {
      type: "User",
      id: "user-1"
    },
    {
      type: "User",
      id: "user-2"
    },
  ]
}

```

1. Or parent model including updated relationship:

```json
{
  data: {
    type: "Team",
    id: "team-1",
    relationships: {
      members: {
        data: [
          {
            type: "User",
            id: "user-1"
          },
          {
            type: "User",
            id: "user-2"
          }
        ]
      }
    }
  }
}

```

---

<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 2, 2018, 3:12pm UTC](https://discuss.jsonapi.org/t/body-of-sucessful-relationship-update-response/1370/2 "2018-09-02T15:12:35Z")

</div>

The first one. (i.e., the response should, I think, always be the same as what the client would get back by immediately making a GET to the same endpoint, assuming GET is supported.)

---

<div class="post-metadata">

**Author:** ![a-komarev](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/a-komarev/32/440_2.png) [@a-komarev](https://discuss.jsonapi.org/u/a-komarev)\
**Post date:** [September 2, 2018, 9:01pm UTC](https://discuss.jsonapi.org/t/body-of-sucessful-relationship-update-response/1370/3 "2018-09-02T21:01:34Z")

</div>

Yeah. I’ve thought this way too. But after starting to implement relationship endpoints in real project I’ve understood that developers should require to implement additional mechanisms for updating relations in their local storages instead of simple resource data merge. I’m not talking against returning first solution, just explaining why I’ve started to doubt.

This solution will require additional serializer on backend, additional frontend resource relationship’s merge mechanisms, but as you correctly noted will bring consistency with GET requests and should reduce server load.

---

<div class="post-metadata">

**Author:** ![jelhan](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/jelhan/32/822_2.png) [@jelhan](https://discuss.jsonapi.org/u/jelhan)\
**Post date:** [November 5, 2018, 10:48pm UTC](https://discuss.jsonapi.org/t/body-of-sucessful-relationship-update-response/1370/4 "2018-11-05T22:48:44Z")

</div>

Server must return with a `204 No Content` in your given example:

> A server **MUST** return a `204 No Content` status code if an update is successful and the representation of the resource in the request matches the result.

Server must only return a `200 OK` in this two cases:

> If a server accepts an update but also changes the targeted relationship(s) in other ways than those specified by the request, it **MUST** return a `200 OK` response. The response document **MUST** include a representation of the updated relationship(s).
> 
> A server **MUST** return a `200 OK` status code if an update is successful, the client’s current data remain up to date, and the server responds only with top-level [meta](https://jsonapi.org/format/#document-meta) data. In this case the server **MUST NOT** include a representation of the updated relationship(s).
