-
Notifications
You must be signed in to change notification settings - Fork 0
Home
jayoungers edited this page Oct 18, 2018
·
3 revisions
PatchMap
is a .Net library intended to simplify the process of creating and updating entities in your REST based applications.
After defining a map for an entity (a Blog
, for example), you can Insert, Update, and Patch that entity using the same code:
[RoutePrefix("api/blogs")]
public class BlogsController : BaseController
{
public BlogsController(ExampleContext dbContext) : base(dbContext) { }
[HttpPost, Route("")]
public PatchCommandResult<BlogViewModel> Insert(BlogViewModel blog)
{
return new BlogPatchCommand(DbContext).Execute(null, blog.ToPatchOperations());
}
[HttpPut, Route("{id}")]
public PatchCommandResult<BlogViewModel> Update(int id, BlogViewModel blog)
{
return new BlogPatchCommand(DbContext).Execute(id, blog.ToPatchOperations());
}
[HttpPatch, Route("{id}")]
public PatchCommandResult<BlogViewModel> Patch(int id, List<JsonPatch> patches)
{
return new BlogPatchCommand(DbContext).Execute(id, patches.ToPatchOperations<BlogViewModel>());
}
}
The library consists of three parts:
- A method to convert HTTP Patch messages into a list of
PatchOperation
. - A method to convert any
object
into a list ofPatchOperation
. - A
Mapper
, which can take some sort of Entity and a list ofPatchOperation
, and given a set of defined Maps, apply thePatchOperation
s to the target Entity.
Concepts
PatchMap Library
Examples