GithubHelp home page GithubHelp logo

marusyk / simple.httppatch Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 7.0 51 KB

Simple.HttpPatch implementation for .NET to easily allow & apply partial REST-ful service (through Web API) using Http Patch

License: MIT License

C# 50.34% Shell 20.15% PowerShell 29.52%
webapi http-patch restful-api json patch rest hacktoberfest

simple.httppatch's Introduction

HttpPatch

AppVeyor Travis build status GitHub (pre-)release NuGet Pre Release NuGet License contributions welcome

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

simple.httppatch's People

Contributors

marusyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simple.httppatch's Issues

Ignore null value for specified properties

This is particularly useful in two cases:

  • when your property is a value type (like int and DateTime) and your client still send a null value for that property. Ignoring null value will avoid exception.

  • when your property is a reference type (which allows null) but you don't want that null overwrites your previous stored data.

Add possibility to create Patch model

Currently we have

[HttpPatch]
public Person Patch([FromBody] Patch<Person> personPatch)
{
    var person = _repo.GetPersonById(1);
    personPatch.Apply(person);
    return person;
}

So, creating of Patch model is doing by Model Binder.
It would be nice to have possibility to create it manually:

[HttpPatch]
public void Patch([FromBody] Patch<Person> personPatch)
{
    var personPatch = new Patch<Person>(personDto)
    var person = _repo.GetPersonById(1);
    personPatch.Apply(person);
    return person;
}

Excluding properties

Nice to have possibility to exclude one or more properties of an entity while applying the changes to the original entity to preserve the original value of the property.

The TrySetMember method is not working; it doesn't execute.

  • The TrySetMember method never executes; therefore, _changedProperties remains empty, and as a result, it doesn't work.
  • I tried with the example from the repository, and I get the same results; it doesn't work.
  • Thank for your time :).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.