Skip to content
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 support #759

Open
dkarlovi opened this issue Sep 20, 2016 · 20 comments
Open

JSON PATCH support #759

dkarlovi opened this issue Sep 20, 2016 · 20 comments

Comments

@dkarlovi
Copy link
Contributor

#147 suggested adding a PATCH support for partials updates, it was closed as PUT already does that.

How about adding a JSON PATCH support? Difference here is you're able to do operations WITH entities, not only ON entites, quoted from Why PATCH is Good for Your HTTP API

PATCH is atomic, which means that if you need to do some complex changes to the state of a resource, you can do it with confidence. It also means that you can create synthetic resources and PATCH them if you need to orchestrate changes to the state of several resources.

@dunglas
Copy link
Member

dunglas commented Sep 21, 2016

It would definitely be a great improvement to have support for JSON PATCH.

@dunglas
Copy link
Member

dunglas commented Sep 21, 2016

On the other end, JSON Merge Patch will be easier to implement, and easier to use client-side.

@teohhanhui
Copy link
Contributor

http://erosb.github.io/post/json-patch-vs-merge-patch/

@asimonf
Copy link

asimonf commented Feb 24, 2017

@dunglas given that the content-type of both methods is different, couldn't both be implemented? I understand that Merge Patch has limitations, but for many cases, it's simplicity could be great for certain applications.

What I mean is, I don't see why we should have to pick one or the other. They are just different formats and both could be supported. If that's ok with you, I might have a go at trying to implement merge patch, time permitting.

@dunglas
Copy link
Member

dunglas commented Feb 25, 2017

Yew we can support both. It should be possible to support JSON MERGE PATCH with just a few modifications to the current system.

@teohhanhui
Copy link
Contributor

Implementing JSON Patch will force us to improve our design. And it will allow us to deprecate the current partial PUT semantics (which is wrong). 😄

@asimonf
Copy link

asimonf commented Feb 27, 2017

@teohhanhui I don't see why both (JSON MERGE and JSON PATCH) can't be implemented. I don't disagree with you and I'm sure if a PR appears for JSON PATCH, @dunglas would be willing to merge assuming it passes review. In my use-case, the simplicity of JSON MERGE trumps the flexibility of JSON PATCH.

@teohhanhui
Copy link
Contributor

teohhanhui commented Feb 28, 2017 via email

@teohhanhui
Copy link
Contributor

teohhanhui commented Feb 28, 2017 via email

@StephenOTT
Copy link

anyone actively working on this?

@dunglas
Copy link
Member

dunglas commented Jul 14, 2017

AFAIK, no. But we should probably consider using JSON Merge Patch instead: https://tools.ietf.org/html/rfc7386

@StephenOTT
Copy link

StephenOTT commented Jul 14, 2017

@dunglas can this issue be closed in favour of #1175 ?

@teohhanhui
Copy link
Contributor

JSON API is only one media type. This is about PATCH support for all of the supported media types, and I'd think especially JSON-LD / Hydra.

@dkarlovi
Copy link
Contributor Author

@dunglas IMO this shouldn't be closed in favor of JSON Merge since Merge is only a partial PUT.

JSON PATCH is a diff to a JSON document so, if a document represents a collection of your resources, you could:

  1. append a new resource into a collection
  2. remove a resource from a collection
  3. re-order (some) collection items without touching (or mentioning) the rest

It solves the partial collection management problem well and IMO it should be kept as a future option.

@bendavies
Copy link
Contributor

bendavies commented Apr 29, 2019

this seems a step too far at the moment.
for the moment, why can we not just make PUT mean PUT semantically, rather than PATCH? is is difficult?

EDIT: from slack

it seems not that hard? we know what attributes are writable for the PUT from serializer, so we can just

  1. treat missing as null. fill missing as null if not provided, or
  2. treat missing as error. throw error as not all required attributes were provided.

@teohhanhui
Copy link
Contributor

@bendavies Yes, but we need to make it opt-in for BC. And when we have proper JSON Patch support, we can deprecate not using the correct semantics.

@alanpoulain
Copy link
Member

JSON Merge Patch support has landed in 2.5.

@teohhanhui
Copy link
Contributor

Let's keep this open as we only support JSON Merge Patch, not JSON Patch.

@teohhanhui teohhanhui reopened this Dec 18, 2019
@Muspi
Copy link

Muspi commented Sep 15, 2020

#Hi, how do you manage partial Validation constraints with PATCH actions?
I'm facing some problems to achieve this, but I do not have solution.

I opened an issue here:
api-platform/api-platform#1637

@DurandA
Copy link

DurandA commented Aug 10, 2022

I am attempting to implement a subset of JSON Patch/RFC 6902 in order to partially update collections. See discussion #4882.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants