ASP.NET Core API - Patch method without using JsonPatchDocument

Viewed 705

Given the following model

public class User
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
}

and lets assume the following as it's Json payload

{
    "id": "b3fe876d-5050-4bd6-af28-c9941d837c18",
    "Name": "John",
    "Address": "Germany"
}

I am trying to patch this via my API endpoint, lets say I need to update Name key, using JsonPatchDocument in .net the payload would be like

 {
    "op": "add",
    "path": "/Name",
    "value": "Jack"
  }

The above works fine!

However we are trying to achieve the same things by sending the same Json payload through the API instead of the Patch specified format. So something like below

{
    "Name": "Jack"
}

So it would only update that specific property/ key in the Json/ Model

Not sure if this is even possible, but this has been brought up by a friend who has implemented this using DJango and Python. Hence we are trying to achieve the same thing in .Net

0 Answers
Related