HttpPatch 1.1.0
dotnet add package HttpPatch --version 1.1.0
NuGet\Install-Package HttpPatch -Version 1.1.0
<PackageReference Include="HttpPatch" Version="1.1.0" />
<PackageVersion Include="HttpPatch" Version="1.1.0" />
<PackageReference Include="HttpPatch" />
paket add HttpPatch --version 1.1.0
#r "nuget: HttpPatch, 1.1.0"
#:package HttpPatch@1.1.0
#addin nuget:?package=HttpPatch&version=1.1.0
#tool nuget:?package=HttpPatch&version=1.1.0
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)
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 | Versions 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. |
-
net6.0
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.