HttpPatch 1.1.0

dotnet add package HttpPatch --version 1.1.0
                    
NuGet\Install-Package HttpPatch -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HttpPatch" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HttpPatch" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="HttpPatch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HttpPatch --version 1.1.0
                    
#r "nuget: HttpPatch, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HttpPatch@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HttpPatch&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=HttpPatch&version=1.1.0
                    
Install as a Cake Tool

HttpPatch

Helpers for a simple HttpPatch using a simple model

If a property is present in the json it will be patched (even to null)

Commit NuGet version (HttpPatch)

Examples

  • Patch Name to "Bob" and description (a nullable property of the resource) to null
{
  "name": "Bob",
  "description": null
}
  • Patch Name to "Bob" and description to "The best Bobertson"
{
  "name": "Bob", 
  "description": "The best Bobertson"
}
  • Patch Name to "Bob" and do not change the description
{
  "name": "Bob"
}

Adding To A Project

Simply use the OptionallyPatched<T> class in your patch requests!

What about validation?

The DataAnnotation attributes will not work "through" the OptionallyPatched<T> class, however there is a workaround for this

A helper base record called BasePatchRequest will pass some attributes down to the underlying value when validating, if it is included in the patch

public record TestResourcePatchRequest(
    [RequiredIfPatched]
    [MinLengthIfPatched(2)]
    OptionallyPatched<string> Name
) : BasePatchRequest

Note that these wrappers RequiredIfPatched are not the actual data annotation attributes but do map 1:1, if you need one that is missing, feel free to add them 😃

What about custom serialization?

JsonConverter attributes on the OptionallyPatched property will not work either, if you need custom serialization of an underlying value, either load the converters globally or place them on the underlying type

Example:

[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public enum ResourceState
{
    Unpublished,
    Published
}

They will work as normal on nested properties, just not the top level OptionallyPatched<T> item

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 452 11/9/2022
1.0.0 650 8/1/2022