Simple.HttpPatch is implementation for .NET (Full framework and Core) to easily allow & apply partial RESTful service (through Web API) using HTTP PATCH method.
You can install the latest version via NuGet.
PM> Install-Package Simple.HttpPatch
See samples folder to learn of to use this library with ASP.NET Core.
Patch a single entity
[HttpPatch]
public Person Patch([FromBody] Patch<Person> personPatch)
{
var person = _repo.GetPersonById(1);
personPatch.Apply(person);
return person;
}
To exclude properties of an entity while applying the changes to the original entity use PatchIgnoreAttribute
.
When your property is a reference type (which allows null) but you don't want that null overwrites your previous stored data then use PatchIgnoreNullAttribute
public class Person
{
public int Id { get; set; }
[PatchIgnore]
public string Name { get; set; }
public int? Age { get; set; }
[PatchIgnoreNull]
public DateTime BirthDate { get; set; }
}
Note: The property with name Id
is excluded by default
For firewalls that don't support PATCH
see this issue
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This project is licensed under the MIT License - see the LICENSE.md file for details