Simple.HttpPatch
Simple.HttpPatch copied to clipboard
Simple.HttpPatch implementation for .NET to easily allow & apply partial REST-ful service (through Web API) using Http Patch
Simple.HttpPatch
Simple.HttpPatch is implementation for .NET (Full framework and Core) to easily allow & apply partial RESTful service (through Web API) using HTTP PATCH method.
Installation
You can install the latest version via NuGet.
PM> Install-Package Simple.HttpPatch
How to use
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
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
License
This project is licensed under the MIT License - see the LICENSE.md file for details