Follow-up from #1816354: Add a REST module, starting with DELETE: The REST module should allow PUT requests to update entities. The request Content-Type format will be hard-coded to JSON-LD for now, everything else will be rejected.
IMO it would be cool to allow partial updates, too. So instead of PUTing the whole resource representation to the endpoint it should be possible to just PUT the title property of a node for example. Strictly speaking this would be the semantics of HTTP PATCH. Clients do not have to retrieve the resource representation beforehand, parse it and replace parts. They can just PUT the parts they are interested in.
Work is done in the PUT-update-1839366 branch in the REST sandbox.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | rest-put-1839366-19.patch | 5.6 KB | klausi |
| #17 | rest-put-1839366-17.patch | 7.68 KB | klausi |
| #17 | rest-put-1839366-17-interdiff.txt | 3.06 KB | klausi |
| #10 | rest-put-1839366-10.patch | 7.05 KB | klausi |
| #10 | rest-put-1839366-10-interdiff.txt | 5.28 KB | klausi |
Comments
Comment #1
webchickThis seems pretty important to having web services in core.
Comment #1.0
klausiadded issue dependencies.
Comment #2
klausiFirst patch that adds a put() method and simpletests.
Interdiff is against the issues mentioned in the summary, please review that.
Comment #2.0
klausitypo
Comment #3
moshe weitzman commentedLooks pretty straightforward to me. Hopefully we can sort the dependencies quickly.
Comment #3.0
moshe weitzman commentedadded link to sandbox
Comment #4
klausiSimple reroll, after #1834288: RESTfully request an entity with JSON-LD serialized response got committed, still depends on #1839346: REST module: POST/create. No other changes.
Comment #5
klausiUpdated patch, now that deserialization basically works.
The question is now how this operation should work on the entity API level. A PUT request has to completely replace the existing entity. Currently with this patch properties that are omitted do not get removed as they should. We also need test cases for this, which we currently do not have.
Partial updates are now discussed in #1826688: REST module: PATCH/update.
Comment #6
klausiSimple reroll after #1839346: REST module: POST/create got committed.
Comment #6.0
klausiremoved GET patch dependency.
Comment #8
klausi#6: rest-put-1839366-6.patch queued for re-testing.
Comment #9
moshe weitzman commentedSounds to me like we should do an entity_create() and pass in all the stuff that came from the incoming PUT. We should make sure that entity->id is set. Then, call entity->save. At no point did we call entity_load(). Sound good?
Comment #10
klausiTo answer myself: the current implementation already replaces the entity as expected, so there is nothing we need to change here. Yay!
I implemented a test case that demonstrates that omitted entity properties are deleted. So I guess this i pretty ready.
Comment #12
klausi#10: rest-put-1839366-10.patch queued for re-testing.
Comment #13
damien tournoud commentedThis feels debatable. HTTP/1.1 just says that:
The intention of the client is to modify an existing resource with a new representation of this resource. The new representation only supersedes the representation that the client would retrieve in a GET method.
As a consequence, only the fields that would be present in the representation that would be generated for that particular client (in a GET request) should be taken into account. Fields that the client doesn't have access to should remain completely unaffected.
Comment #14
moshe weitzman commented@Damien - the existing rest services don't care about access controlled fields either (CREATE, READ, ...). I agree that this is non-ideal and that we need to discuss it in its own issue. I've opened #1866908: Honor entity and field access control in REST Services. In the meanwhile, when you grant a role the rest permissions, you are granting full access to entity fields.
This is ready.
Comment #15
damien tournoud commentedSorry, but this is not ready. The current approach cannot flight. We cannot just throw away the old entity completely, as it can contain technical information that should not be touched (created date, etc.).
Comment #16
damien tournoud commentedPUT has never been intended to be the equivalent of DELETE + PUT. In our case, the proper algorithm for PUT needs to be:
Comment #17
klausiNote: the current code never issues the deletion of an entity (no delete hooks are fired for example). It is simply completely replaced.
New patch:
* Added the 404 logic on entities that don't exist yet, added a test case for that.
* Changed success status code to 204.
Since we do not take entity access control into account in this patch merging or replacing the entity is equivalent, no need to change the code. Entity validation is also a followup issue, since that functionality is still in the works.
Comment #18
mitchell commented#1869338: Support ETag + If-Match for PATCH requests to prevent concurrent updates
Comment #19
klausiRerolled after #1826688: REST module: PATCH/update was committed. No other changes.
Comment #20
moshe weitzman commentedGood to go. We'll tackle entity validation in #1696648: [META] Untie content entity validation from form validation
Comment #21
dries commentedCommitted to 8.x. Thanks.
Comment #22.0
(not verified) commentedremoved committed dependency.