JsonMergePatch
03/21/2021
JsonMergePatch library provides an implementation for json merge patch operations, detailed in RFC7396. The library uses C# source generators to generate the types required for serialization. The Http package provides extension methods for HTTP requests and responses, while the AspNetCore package provides an InputReader implementation.
Resources in REST are typically updated according to the CRUD operations: Create/Update, Read, Delete. JsonMergePatch library enables to use http PATCH method to create and update a resource. Using PATCH operation has several benefits over PUT and POST requests:
Patch can be used for both create and update operations.
Patch payloads for updates can be significantly smaller if majority of the members remain unchanged
Patch solves versioning issues: a new version (V2) of the resource may contain new members. With patch operation V1 clients remain compatible: if a new property is unknown for the client, it will not be sent; on the server side the operation still succeeds, while the new V2 properties are retained. Using PUT operation, the V2 property values would become discarded by a V1 client request.