-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON Patch equivalent structures #193
Comments
Thanks very much for working up these examples and expanding on our discussion! I think of the "JSON Patch equivalent structures" as the "schema" of an API. It's possible to think of an entire API as if it's acting on a single JSON document. We should probably spell out this abstraction in the spec, since it applies to all requests (not just PATCHes). The one thing I would change in your examples is that patch paths should be relative to request paths. If patch paths are considered to be relative, the request path + patch path can be combined to reference a particular entity. I really think the current spec has it wrong in making the patch paths absolute for the whole API, since that approach renders request paths redundant and therefore confusing. Relative paths would allow us to replace the title of a post with:
Instead of:
Similarly, a comment could be removed from a post with:
Instead of:
By using relative paths, API implementers could choose to allow bulk operations at request paths of any depth, even including the root. This would make for a very flexible but complex API. Alternatively, an API might only allow very specific patch operations that modify single entities. Of course, these decisions should all be optional and left up to the needs of each API - but it's nice that the spec could encompass any level of complexity. |
@dgeb Edit: I like it :) Add To-Many Relationship: [{ "op": "add", "path": "/comments/-", "value": "1" }] (Is that minus correct?) and Change To-One Relationship: [{ "op": "replace", "path": "/author", "value": "3" }] Is that correct? |
@MajorBreakfast those ops look good to me 👍 |
But the JSON patch is just for changing fields and relationships, right? We don't support the creation of documents. |
Correct - that is the current status. As I see it, support for JSON PATCH could optionally be extended further by some APIs. In my opinion, this is the right approach for bulk operations. I think JSON API should have an opinion about these use cases. |
❤️ It's possible to think of an entire API as if it's acting on a single JSON document. We should probably spell out this abstraction in the spec, since it applies to all requests (not just PATCHes). @dgeb this approach makes a lot of sense to me. You also mention in #176 of not including 'links' in the JSON Patch path, still believe in that? Is it purely for simplicity on the client end? |
@guillec I've thought about having the "/links" in the URL. I think now that we should include it. It makes the URLs a bit longer but not by much. I think that leaving it out simply hides something that is not worth hiding. Also: We're defining the JSON patch equivalent structure. It's defined for the "links". I'm for specifying that it has to be in there. |
How do you feel about #198? Do you think this thread can obsolete it? |
@MajorBreakfast yeah I am leaning towards requiring it, if the only reason is simplicity for the client. I feel that the more we change the response body from the JSON Patch equivalent the more confusion there will be. |
My rationale in #176 for not including Upon a little reflection, I now realize that was a false equivalency: there's a difference between a link and its associated linked resource. We need to be able to distinguish between the two with JSON Pointers. For example, one might want to delete a link from a post to its author without also deleting the author. Bottom line: I believe |
@dgeb ahhh ok thanks for the explanation! 👍 on the bottom line |
Adding to 1.0 because #193 (comment) |
Closed via #237 which adds a description of the "reference document" used to determine an API's recommended URL structure. |
On issue #176 there is a discussion about how to possibly map JSON Patch paths.
I've added some examples here for further discussion.
How to replace the title of a post:
How to remove comment 5:
How to replace author type with a new value of "human":
How to replace author type with id of 1 to "not-dog":
How to remove multiple posts:
The text was updated successfully, but these errors were encountered: