Skip to content

Updating a to-many relationship in the URL-based approach #175

@fancyremarker

Description

@fancyremarker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy