PatchRequestMinimal 7.0.18

dotnet add package PatchRequestMinimal --version 7.0.18                
NuGet\Install-Package PatchRequestMinimal -Version 7.0.18                
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="PatchRequestMinimal" Version="7.0.18" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PatchRequestMinimal --version 7.0.18                
#r "nuget: PatchRequestMinimal, 7.0.18"                
#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.
// Install PatchRequestMinimal as a Cake Addin
#addin nuget:?package=PatchRequestMinimal&version=7.0.18

// Install PatchRequestMinimal as a Cake Tool
#tool nuget:?package=PatchRequestMinimal&version=7.0.18                

Patch Request for Minimal API

helps to process patch request from the minimalAPI

Installation

Install my-project with dotnet-cli

  dotnet add package PatchRequestMinimal --version 7.0.18

Features

  • Replace
  • Remove

Usage/Examples

using PatchRequest;

//================================================================
// Request DTO

public sealed record NestedModel(Guid Id, string Name, int? Value);

public sealed record RequestModel(string Title, 
    int Number,
    NestedModel NestedObject,
    IEnumerable<int> IntArray);

//================================================================
// Destination Entity 

public sealed record NestedEntity(Guid Id, string Name, int? Value);
public sealed record SourceEntity(string Title, 
    int Number,
    NestedEntity NestedObject,
    IEnumerable<int> IntArray);

//================================================================
// Patch endpoint into Program.cs

app.MapPatch("patch-test/{id}", (Guid id, 
    [FromBody] PatchRequest<RequestModel> request) =>{
    SourceEntity entity = dbContext.Set<SourceEntity>()
        .First(x => x.Id == id);

    RequestResult result = request.Apply(entity);

    if(result.Succeeded){
        dbContext.Update(entity);
        dbContext.SaveChanges();

        return Results.Ok(new { Message = "Some property values changed." })
    }

    var errors = result.Messages.Select(x => x.Description);

    return Results.BadRequest(errors);
});

//================================================================
// PatchRequest<T> example requests
/*
    {
        "operations":[
            {
                "op": "replace",
                "prop": "title",
                "value": "new value"
            },
            {
                "op": "replace",
                "prop": "nestedObject.name",
                "value": "nested object name new value"
            },
            {
                "op": "remove",
                "prop": "nestedObject.value",
                "value": null
            },
            {
                "op": "replace",
                "prop": "intArray",
                "value": [1, 2, 3, 4]
            }
        ]
    }
*/
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.