consume api patch request c# code example

Example 1: rest api c# json patch

[
    { "op": "add", "path": "/foo", "value": "bar"},
    { "op": "replace", "path": "/baz", "value": "boo" }
]

Example 2: rest api c# json patch

JsonPatchDocument<SimpleDTO> patchDoc = new JsonPatchDocument<SimpleDTO>();

// add "4" to a list of integers at position 0
patchDoc.Add<int>(o => o.IntegerList, 4, 0);

// add "5" to the end of that list
patchDoc.Add<int>(o => o.IntegerList, 5);

// remove the current value of StringProperty
patchDoc.Remove<string>(o => o.StringProperty);

// remove the value at position two from a list of integers
patchDoc.Remove<int>(o => o.IntegerList, 2);

// replace StringProperty with value "B"
patchDoc.Replace<string>(o => o.StringProperty, "B");

// replace value at position 4 in a list of integers with value 5
patchDoc.Replace<int>(o => o.IntegerList, 5, 4);

//copy value IntegerValue to position 0 in a list of integers
patchDoc.Copy<int>(o => o.IntegerValue, o => o.IntegerList, 0);

// move the integers at position 0 in a list of integers to position 1 in that same list
patchDoc.Move<int>(o => o.IntegerList, 0, o => o.IntegerList, 1);