A library that allows usage of JsonPatch with Nancy
C#
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
samples/Nancy.JsonPatch.Core.Demo
src/Nancy.JsonPatch.Core
.gitignore
LICENCE
Nancy.JsonPatch.Core.sln
NuGet.config
README.md

README.md

Nancy.JsonPatch.Core

A library that allows usage of JsonPatch with Nancy

private Contact contact = new Contact
{
    FirstName = "Vincent",
    LastName = "Vega",
    Age = 42,
    Links = new List<string> { "http://vincentvega.com" }
};

Patch("/", _ =>
{
    var incomingModel = this.Bind<List<Operation<Contact>>>();
    var patch = new JsonPatchDocument<Contact>(incomingModel, new DefaultContractResolver());
    var patched = contact.Copy();

    patch.ApplyTo(patched, ModelValidationResult);

    if (!ModelValidationResult.IsValid)
    {
        return Response.AsJson(ModelValidationResult.Errors).WithStatusCode(422);
    }

    var model = new { original = contact, patched = patched };

    return model;
});