rest - How to update a collection using json patch -
i can't find samples on way use json patch update collection. in fact, want use method patch
on collection rest resource in order update associated collection without sending again whole collection. wonder if json patch match describe operations do: add elements or remove elements. elements complex, meaning aren't primitive elements.
below there more details. let's take sample of resource contacts
:
get /contacts [ { "id": "1", "lastname": "last name 1", "firstname": "first name 1" }, { "id": "2", "lastname": "last name 2", "firstname": "first name 2" }, { "id": "3", "lastname": "last name 3", "firstname": "first name 3" }, (...) ]
here patch
request use i'm not sure json patch compliant:
patch /contacts [ { "op": "add", "value": { "firstname": "my first name", "lastname": "my last name" } }, { "op": "remove", "path": "id=='1'" } ]
my main issue how identify element delete based on field id
. there dedicated expression this? thought like: id=='1'
.
last question: response content targeted json patch?
thanks avance help! thierry
you should able use path resource deleted.
patch /contacts [ { "op": "add", "value": { "firstname": "my first name", "lastname": "my last name" } }, { "op": "remove", "path": "/contacts/1" } ]
looking around, there seems confusion this, standard says "the "remove" operation removes value @ target location" example:
{ "op": "remove", "path": "/a/b/c" }
Comments
Post a Comment