dimanche 3 septembre 2017

Ember and JSON API spec: Updating relationships as part of resource update requests

Regarding Ember's use of the JSON API spec, there is a bit I need help with.

When updating a resource, you may update the relationships as part of the same request. Missing relationships should not be interpreted as deletion, says the spec. But it ALSO has examples referring to relationship updates as "complete replacement."

First it says this... "Any or all of a resource’s relationships MAY be included in the resource object included in a PATCH request.

If a request does not include all of the relationships for a resource, the server MUST interpret the missing relationships as if they were included with their current values. It MUST NOT interpret them as null or empty values."

But then it shows this:

"... the following PATCH request performs a complete replacement of the tags for an article:

PATCH /articles/1 HTTP/1.1 Content-Type: application/vnd.api+json Accept: application/vnd.api+json

{ "data": { "type": "articles", "id": "1", "relationships": { "tags": { "data": [ { "type": "tags", "id": "2" }, { "type": "tags", "id": "3" } ] } } } }"

I interpret this as meaning I could neglect to include, say, "author" in the above relationships section, and the server would not change the relationships between the article and it's author. But if I submitted the above JSON and the article already had three tags, those three would be unlinked and the two specified would be linked in their place.

I was having trouble explaining the difference to someone, and wanted confirmation before I brought it up again.




Aucun commentaire:

Enregistrer un commentaire