-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
ASP.NET Core 9 Web API Cookbook
By :
Using a PATCH request, we can update specific fields of a data entity (resource) without sending the entire object to the endpoint. In this recipe, we will leverage the JsonPatchDocument library to target and modify only the fields you need to change. This approach ensures minimal data transfer and precise updates to your resources.
The code for the starter project resides here: chapter02\start\JsonPatchDocument. This recipe picks up where the previous one left off.
dotnet add package Microsoft.AspNetCore.JsonPatch dotnet add package Microsoft.AspNetCore.Mvc.NewtonSoftJson
We are not going to use System.Text.Json as our JSON provider in this example. Although it is possible to set up JsonPatch with System.Text.Json, it is more work. Import the Mvc.Formatters namespace and register that you would like to use Newtonsoft for Json on our...