How to implement Partial Updates (PATCH) in Restful Web API (.NET/ JSON/ EF6) Server side

c# entity-framework-6 json patch rest

Question

I have been working on a Web API project (Restful), where the size of models (and respective table) is pretty huge, hence there is an absolute need of Partial Updates.

I have reviewed the option of POST to a subsection of the model, but given that the model has huge amount of fields (and custom fields), don't think it feasible to expose that many URIs).

I understand that using PATCH verb, I can allow a client to do partial updates, but I am struggling to conceptualize how should I capture the same on the server side and then find out what's changed (post JSON to model conversion) so that I can distinguish what field(s) are explicitly set as NULL by client (as she wanted to update field) Vs. what is NULL as a result of no update.

Should I use a custom mapper? or should I create generic properties and capture state at a field level?

I have searched (and still doing) net and here at SOF.com, but there is nothing authoritative/ concrete that I have found, so reaching out to pros for feedback.

appreciate your help!

1
1
10/11/2016 6:50:16 AM

Popular Answer

KevinDockx created plugin to MVC that handle PATCH. Here is nuget link https://www.nuget.org/packages/Marvin.JsonPatch/

This plugin is RFC 6902 implementation for .NET..

basically when you send json patch from your client you have to build array of operations

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

Of course it only matters if you want to follow Specification. In other case (I mean your own understanding of how PATCH works) you have to implement your custom logic.

EDIT

Personally I found that only 'replace' operation was useful in my use-cases because of flat nature of my DTOs.

0
10/11/2016 7:06:13 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow