-
Notifications
You must be signed in to change notification settings - Fork 890
Closed
Milestone
Description
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:
PATCH /posts/1 # JSON Patch Document: [ { "op": "replace", "path": "/posts/1/title", "value": "New Title" } ] # JSON API resource: { "posts": [{ "id": "1", "title": "Old Title" }] } # JSON Patch equivalent structure: { "posts": { "1": { "id": "1", "title": "The title" } } }
How to remove comment 5:
PATCH /posts/1 # JSON Patch Document: [ { "op": "remove", "path": "/posts/1/comments/5" } ] # JSON API resource: { "posts": [{ "id": "1", "links": { "comments": [ "1", "3", "5", "7" ] } }] } # JSON Patch equivalent structure: { "posts": { "1": { "id": "1", "links": { "comments": { "1": "1", "3": "3", "5": "5", "7": "7" } } } } }
How to replace author type with a new value of "human":
PATCH /posts/1 # JSON Patch Document: [ { "op": "replace", "path": "/posts/1/author/type", "value": "human" } ] # JSON API resource: { "posts": [{ "id": "1", "title": "Rails is Omakase", "links": { "author": { "href": "http://example.com/people/17", "id": "17", "type": "people" } } }] } # JSON Patch equivalent structure: { "posts": { "1": { "id": "1", "links": { "author": { "href": "http://example.com/people/17", "id": "17", "type": "people" } } } } }
How to replace author type with id of 1 to "not-dog":
PATCH /posts/1 # JSON Patch Document: [ { "op": "replace", "path": "/posts/1/authors/1", "value": "not-dog" } ] # JSON API resource: { "posts": [ { "id": "1", "title": "One Type Purr Author", "links": { "authors": [ { "href": "http://example.com/people/9", "id": "9", "type": "people" }, { "href": "http://example.com/cats/1", "id": "1", "type": "cats" } ] } } ] } # JSON Patch equivalent structure: { "posts": { "1": { "id": "1", "links": { "authors": { "9": { "href": "http://example.com/people/9", "id": "9", "type": "people" }, "1": { "href": "http://example.com/cats/1", "id": "1", "type": "cats" } } } } } }
How to remove multiple posts:
PATCH /posts # JSON Patch Document: [ { "op": "remove", "path": "/posts/1" }, { "op": "remove", "path": "/posts/2" }, { "op": "remove", "path": "/posts/3" }, { "op": "remove", "path": "/posts/4" } ] # JSON API resource: { "posts": [ { "id": "1", "title": "One Type Purr Author", }, { "id": "2", "title": "One Type Purr Author", }, { "id": "3", "title": "One Type Purr Author", }, { "id": "4", "title": "One Type Purr Author", } ] } # JSON Patch equivalent structure: { "posts": { "1": { "id": "1", "title": "One Type Purr Author", }, "2": { "id": "2", "title": "One Type Purr Author", }, "3": { "id": "3", "title": "One Type Purr Author", }, "4": { "id": "4", "title": "One Type Purr Author", } } }
Metadata
Metadata
Assignees
Labels
No labels