Removing items from nested collections by UID #331
-
Problem definitionThe webapi currently has implemented JSON Patch according the RFC 6902 IETF specs. However, these specifications don't cover a convenient way to remove nested collection items by UID. One of our goals was to do "canonical updates", i.e. being able to update an object (with nested collections) by issuing a single HTTP request. The inability to remove nested collection items by UID means we haven't reached our goal yet. Possible solutionsWe have several options to address this issue which are listed below as "suggested answers". Please upvote the solution that seems most appropriate to you and reply if you like to add your motivation. If you like one of the options, but would like to see some minor alterations, please add your suggestion as a reply. If you have a completely different option in mind, please suggest a new answer at the bottom. A note about adding nested collection itemsThe text above doesn't cover adding items at all because that is covered by the IETF specs:
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 20 replies
-
Option A - forget about canonical updates and use the existing APIWhile I don't think this is actually a viable option, I feel I should still be mentioned here for completeness. We do already have a dedicated API for managing nested collections (see docs). So we could just:
This would be something we have to do everywhere we encounter nested collections. As such it would mean a lot of additional work in our apps, and also more network traffic. |
Beta Was this translation helpful? Give feedback.
-
Option B - hijack the "replace by index" operationAlthough the IETF specs don't include a way to remove collection items by UID, they do include a way to remove items by index: { "op": "remove", "path": "/nestedCollection/1" } Since an index is (a string representation of) an integer, and a UID has a fixed length and a combination of alphanumeric characters, it is possible to differentiate between the two. As such we could implement things as follows: // by index
{ "op": "remove", "path": "/nestedCollection/1" }
// by UID
{ "op": "remove", "path": "/nestedCollection/oXD88WWSQpR" } We are not adding any new operators here, but extending what one of the IETF operators is capable of doing. We need to consider if that is a good or a bad thing. |
Beta Was this translation helpful? Give feedback.
-
Option C - adopt the "value-based array operations" proposalThis proposal is already 6 year old and suggests this should be a valid JSON Patch operation: { "op": "remove", "path": "/nestedCollection/-", "value": { "id": "oXD88WWSQpR"} } I'm not sure this proposal will ever get adopted, and also find it quite generic. How would we deal with cases where |
Beta Was this translation helpful? Give feedback.
-
Option D - add a custom operatorWe have discussed two variants of this: D1 - a regular custom operator { "op": "remove-by-uid", "path": "/nestedCollection/oXD88WWSQpR" } D2- a name-spaced custom operator { "op": "dhis2-remove-by-uid", "path": "/nestedCollection/oXD88WWSQpR" } By using a custom operator we don't cause any surprises. Since this is not part of the standard, users will need to consult our documentation to become aware of its existence. But in all fairness, that would be an issue for all solutions since the IETF specs don't cover this feature anyway, and the only other way to delete items from nested collections would be to read the docs on our collection api. |
Beta Was this translation helpful? Give feedback.
-
Option E - add a custom
|
Beta Was this translation helpful? Give feedback.
-
Option F - add a custom
|
Beta Was this translation helpful? Give feedback.
-
Option G - custom operation with valid JSON Pointer string for
|
Beta Was this translation helpful? Give feedback.
Option G - custom operation with valid JSON Pointer string for
path
This option is the result of a meeting held by Team Platform Frontend and from its perspective the most preferable syntax. It is inspired by option D1 above, but takes into account the fact that
/nesteCollection/ID
would make thepath
an invalid JSON Pointer.Some motivations for preferring this syntax: