# Why are 'type' and 'id' attributes required in an update request?

**URL:** <https://discuss.jsonapi.org/t/why-are-type-and-id-attributes-required-in-an-update-request/194>\
**Category:** Uncategorized\
**Created:** [November 11, 2015, 2:06pm UTC](https://discuss.jsonapi.org/t/why-are-type-and-id-attributes-required-in-an-update-request/194 "2015-11-11T14:06:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bram](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/bram/32/117_2.png) [@bram](https://discuss.jsonapi.org/u/bram)\
**Post date:** [November 11, 2015, 2:06pm UTC](https://discuss.jsonapi.org/t/why-are-type-and-id-attributes-required-in-an-update-request/194/1 "2015-11-11T14:06:43Z")

</div>

I am implementing a new API and follow the json api spec. (partial) updates are done using the PATCH request (on single resources). This means the request is always send to: /resource/{id}/

What I don’t understand is the requirement to add the ‘type’ and ‘id’ attributes in the request as described here: [http://jsonapi.org/format/#crud-updating](http://jsonapi.org/format/#crud-updating)

Both of them are known because of the endpoint URL. E.G. an update to an article with id 5 is always done on ‘/articles/5’ but still its required by the spec to add both the id and type attributes.

Why is this?

---

<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:** [November 12, 2015, 11:49am UTC](https://discuss.jsonapi.org/t/why-are-type-and-id-attributes-required-in-an-update-request/194/2 "2015-11-12T11:49:19Z")

</div>

Basically, it’s for consistency, because the `type` and `id` can’t be inferred in all cases, and we don’t want clients have to know/think about when it’s needed and when it isn’t. Here’s a relevant passage from the spec about `type`:

> Note: The `type` member is required in every resource object throughout requests and responses in JSON API. There are some cases, such as when POSTing to an endpoint representing heterogenous data, when the `type` could not be inferred from the endpoint. However, picking and choosing when it is required would be confusing; it would be hard to remember when it was required and when it was not. Therefore, to improve consistency and minimize confusion, `type` is always required.

And, as we expand the spec in new directions (e.g. [#795](https://github.com/json-api/json-api/issues/795)-style operations), there’ll likely only be more cases where the ability to infer type/id breaks down.

---

<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:** [November 12, 2015, 1:18pm UTC](https://discuss.jsonapi.org/t/why-are-type-and-id-attributes-required-in-an-update-request/194/3 "2015-11-12T13:18:24Z")

</div>

> [@bram](#):
>
> Both of them are known because of the endpoint URL.

In REST (and HTTP), URLs are supposed to be opaque. JSON API doesn’t place any particular restriction on what your URLs look like, so we cannot guarantee that you could do any kind of inference from the URL.
