It could be great to support PATCH method to update an item, using json-patch for example.
PR are very welcome!
As a side note, partial update trough the PUT method is supported: just don't submit ignore properties you don't want to update.
@dunglas
Are you sure partial update through PUT is working ? In my case, it replaces all non specified properties with null value.
@ZeBigDuck I'm pretty sure, it's even tested.
@dunglas My bad, updating the bundle fixed this :)
Thank you!
I'm closing this PR as this wasn't updated by the author for a while and there is this partial update support with PUT.
Doing partial updates with HTTP PUT is semantically wrong. #759 is the right way to go.
Related reading: http://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/
partial PUT is never RESTful
—Roy T. Fielding
What about JSON MERGE? It will be very easy to implement in API Platform (it's only a matter of registering a new PATCH operation): https://tools.ietf.org/html/rfc7396
We'll have a problem with null value, for one...
JSON Merge Patch is too simplistic.
We'll have a problem with null value, for one...
could you please explain what problems are you talking about?
The JSON Merge Patch specification states:
Null values in the merge
patch are given special meaning to indicate the removal of existing
values in the target.For example, given the following original JSON document:
{
"a": "b",
"c": {
"d": "e",
"f": "g"
}
}Changing the value of "a" and removing "f" can be achieved by
sending:PATCH /target HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json{
"a":"z",
"c": {
"f": null
}
}When applied to the target resource, the value of the "a" member is
replaced with "z" and "f" is removed, leaving the remaining content
untouched.This design means that merge patch documents are suitable for
describing modifications to JSON documents that primarily use objects
for their structure and do not make use of explicit null values. The
merge patch format is not appropriate for all JSON syntaxes.
In API Platform, we use PHP classes to represent document's structures. Obviously, we cannot remove the property of the class when a null value is sent.
What we may do is considering that when the value of a property is null, it is not included in the generated JSON document during the serialization process (it's the behavior of JMS Serializer IIRC).
However, it's not the current behavior of the Serializer component. We may add a new option to change this default, and implement properly JSON Merge Patch.
Hey guys!
Do you know why when PATCHing with Api Platform it still tries to do an INSERT in the DB, not an UPDATE?
Is it just not yet implemented? If so, how would you advice doing a manual PATCHing system on top of you tools? :)
@Itaelle It's not implemented yet. I don't know of an ETA, but it's always high on my to-do list. :laughing:
Closing as duplicate let's continue to keep track of this in https://github.com/api-platform/core/issues/759
Most helpful comment
PR are very welcome!
As a side note, partial update trough the
PUTmethod is supported: just don't submit ignore properties you don't want to update.