The RFC 6902 defines a lot of things and clearly. Except two related things:
- How do you patch a table that is joined to the resource?
- And when the join has multiple rows?
Eg.
GET /news/123
[
{"title": "Hello", "contents": "World", "categories": [1, 2, 3]}
]
Where the results come from these DB tables and columns:
title = news.title
contents = news.contents
categories = newscategories_mapping WHERE newscategories_mapping.newsID = news.id
So, if I send a patch:
PATCH /news/123
[
{"op": "replace", "path": "/title", "value": "New Title"}
]
It is very straightforward. But how about when I want to update the Categories of the same resource? Ie. the "joined" table.
PATCH /news/123
[
{"op": "replace", "path": "/categories", "value": [4, 5]}
]
Also, notice two things:
- None of the existing values are included.
- The amount is less than the original (2 values instead of 3)
Let's say the original values before the patch are in newscategories_mapping.id
20, 21 and 22.
Question 1: Should the new /categories
value 4
replace id=20, and value 5
replaces id=21? Or should id=20, id=21 and id=22 be deleted and the new values get new IDs id=23 and id=24?
Question 2: Should id=22 be deleted, even though that was not explicitly requested?
Question 3: Or should the above not be done at all, and I should instead have a separate endpoint for patching each of the Categories? So, eg. PATCH /news/123/categories/20
and PATCH /news/123/categories/21
?