-
Notifications
You must be signed in to change notification settings - Fork 890
Description
It's not clear to me from the spec how a to-many relationship should be updated in the URL-based approach. Consider the following example from the spec:
{
"posts": [{
"id": "1",
"links": {
"comments": "http://example.com/comments/5,12,17,20"
}
}]
}
Say I want to remove the comment with ID 5 from this post's comments. According to the spec, I should issue a PATCH
request with a remove
operation, a la:
PATCH /posts/1
[
{ "op": "remove", "path": "/posts/0/links/comments/5" }
]
But in this case, this operation doesn't represent a valid JSON Patch operation on the original document. Perhaps the crux of the problem is that at one point the spec states:
While to-many relationships are represented as a JSON array in a GET response, they are updated as if they were a set.
But in the case of the URL-based approach, the to-many relationship is represented as a string, not an array.
One potential answer is that instead of representing editable to-many relationships in the form "http://example.com/comments/5,12,17,20"
, one should always use an opaque URL of the form "http://example.com/posts/1/comments"
, and then issuing a remove
operation on the array elements of this resource.
Alternatively, the spec could allow for listing to-many references as an array of URLs, a la:
{
"posts": [{
"id": "1",
"links": {
"comments": [
"http://example.com/comments/5",
"http://example.com/comments/12",
"http://example.com/comments/17",
"http://example.com/comments/20"
]
}
}]
}
And then issuing a remove
operation:
PATCH /posts/1
[
{ "op": "remove", "path": "/posts/0/links/comments/http:~1~1example.com~1comments~15" }
]
Which of these two options seems more in line with the spec's intention? I'd prefer not to use the "URL shorthand" approach described in the spec, even though it provides another solution.