Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created October 9, 2012 08:16
Show Gist options
  • Save tugberkugurlu/3857303 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/3857303 to your computer and use it in GitHub Desktop.

Assuming you have the following object:

public class Person { 
    
    public string Name { get; set; }
    public string Surname { get; set; }
    public int Age { get; set; }
}

and got a PATCH request as below:

[{"replace": "/name", "value": "tugberk"}]

and assuming we have a json-patch formatter. Wouldn't you get the following result?

public class PeopleController : ApiController { 

    //new Person { Name = "tugberk", Surname = null, Age = 0 }
    public Person PatchPerson(Person person) { 
        
        //...
    }
}
@tugberkugurlu
Copy link
Author

Ok, so IPatchCommand is some sort of a Dictionary or has a Dictionary property? If so, it seems doable to me as I indicated that it would be possible to do this with dynamic or JToken.

@benfoster
Copy link

It would have a collection of PatchingOperation objects like the RavenDB API. The Media Type Formatters job will be simply to know how to create one of these objects based on the JSON-Patch specification. It would be down to the logic in the controller to understand how to patch the object. This, in my opinion, is the tough part - translating a patch operation into a n update on an object.

@tugberkugurlu
Copy link
Author

Yes, right. That's really the hard part and it would change depending on the data store system you use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment