CommonNetFuncs.Web.Api 4.1.7

dotnet add package CommonNetFuncs.Web.Api --version 4.1.7
                    
NuGet\Install-Package CommonNetFuncs.Web.Api -Version 4.1.7
                    
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="CommonNetFuncs.Web.Api" Version="4.1.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommonNetFuncs.Web.Api" Version="4.1.7" />
                    
Directory.Packages.props
<PackageReference Include="CommonNetFuncs.Web.Api" />
                    
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 CommonNetFuncs.Web.Api --version 4.1.7
                    
#r "nuget: CommonNetFuncs.Web.Api, 4.1.7"
                    
#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 CommonNetFuncs.Web.Api@4.1.7
                    
#: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=CommonNetFuncs.Web.Api&version=4.1.7
                    
Install as a Cake Addin
#tool nuget:?package=CommonNetFuncs.Web.Api&version=4.1.7
                    
Install as a Cake Tool

CommonNetFuncs.Web.Api

License NuGet Version nuget

This project contains helper methods for several common functions required by API applications that interact with databases using Entity Framework Core. Works in combination with the BaseDbContextActions class in CommonNetFuncs.EFCore package.

Contents


GenericEndpoints

Provides a set of reusable ControllerBase methods for common CRUD and patch operations in MVC controller-based API endpoints. Each method accepts an IBaseDbContextActions instance and returns an ActionResult<T>, making them easy to delegate to from thin controller actions.

GenericEndpoints Usage Examples

<details> <summary><h3>Usage Examples</h3></summary>

CreateMany
[HttpPost("many")]
public Task<ActionResult<IEnumerable<MyEntity>>> CreateMany(IEnumerable<MyEntity> models)
    => _endpoints.CreateMany(models, _db);
Delete
[HttpDelete]
public Task<ActionResult<MyEntity>> Delete(MyEntity model)
    => _endpoints.Delete(model, _db);
Patch

Applies a JSON Patch document to an entity located by primary key. Returns Ok with the patched entity or NoContent if not found.

[HttpPatch("{id}")]
public Task<ActionResult<MyEntity>> Patch(int id, JsonPatchDocument<MyEntity> patch)
    => _endpoints.Patch<MyEntity, MyDbContext>(id, patch, _db);

</details>

GenericMinimalEndpoints

Provides static methods for common CRUD and patch operations designed for use in ASP.NET Core minimal API endpoints. Each method accepts an IBaseDbContextActions instance and returns strongly-typed Microsoft.AspNetCore.Http.HttpResults results (Results<Ok<T>, NoContent> or Results<Ok<T>, NoContent, ValidationProblem>), making them directly usable as minimal API route handlers.

GenericMinimalEndpoints Usage Examples

<details> <summary><h3>Usage Examples</h3></summary>

CreateMany Minimal API

Creates multiple entities and saves them to the database. Returns Ok with the created entities on success, or NoContent on failure.

app.MapPost("/entities", (IEnumerable<MyEntity> models, IBaseDbContextActions<MyEntity, MyDbContext> db) =>
    GenericMinimalEndpoints.CreateMany(models, db));
Patch Minimal API

Applies a JSON Patch document to an existing entity located by primary key. Validates the patched model and returns Ok with the updated entity, ValidationProblem if validation fails, or NoContent if the entity is not found.

app.MapPatch("/entities/{id}", (int id, JsonPatchDocument<MyEntity> patch, IBaseDbContextActions<MyEntity, MyDbContext> db) =>
    GenericMinimalEndpoints.Patch<MyEntity, MyDbContext>(id, patch, db));

</details>


GenericMinimalDtoEndpoints

Provides static methods for common CRUD, patch, and update operations for minimal API endpoints that use separate input and output DTO types. Input DTOs are mapped to the entity model before database operations and the result is mapped to the output DTO before returning. Returns Results<Ok<TOutDto>, NoContent> or Results<Ok<TOutDto>, NoContent, ValidationProblem>.

GenericMinimalDtoEndpoints Usage Examples

<details> <summary><h3>Usage Examples</h3></summary>

CreateManyDto

Creates multiple entities from input DTOs, saves them, and returns the created records mapped to the output DTO type.

app.MapPost("/entities", (IEnumerable<MyInDto> models, IBaseDbContextActions<MyEntity, MyDbContext> db) =>
    GenericMinimalDtoEndpoints.CreateMany<MyEntity, MyDbContext, MyInDto, MyOutDto>(models, db));
Update

Retrieves an existing entity by primary key, overwrites its properties from the input DTO, validates the result, and saves. Returns Ok with the updated record mapped to the output DTO, ValidationProblem if validation fails, or NoContent if the entity is not found.

app.MapPut("/entities/{id}", (int id, MyInDto dto, IBaseDbContextActions<MyEntity, MyDbContext> db) =>
    GenericMinimalDtoEndpoints.Update<MyEntity, MyDbContext, MyInDto, MyOutDto>(id, dto, db));

</details>



MsgPack

A set of focused components for adding MessagePack support to ASP.NET Core minimal API applications. Unlike a single monolithic middleware, the functionality is split into a request middleware and an endpoint output filter so each can be applied independently.

MsgPackRequestMiddleware

Converts a MessagePack-encoded request body to JSON before the endpoint handler runs, allowing standard [FromBody] parameter binding to work unchanged. Register it in the pipeline before routing.

<details> <summary><h3>Usage Examples</h3></summary>

UseMsgPackRequestBody

Registers MsgPackRequestMiddleware globally so every endpoint accepts MessagePack request bodies. Optionally accepts custom MessagePackSerializerOptions; defaults to MessagePackSerializer.DefaultOptions when null.

// Program.cs
// Default options
app.UseMsgPackRequestBody();

// Custom options (e.g. with FlexibleDecimalResolver)
app.UseMsgPackRequestBody(MessagePackSerializerOptions.Standard
    .WithResolver(CompositeResolver.Create(
        FlexibleDecimalResolver.Instance,
        StandardResolver.Instance)));

app.MapPost("/entities", (MyEntity entity) => Results.Ok(entity));

</details>


MsgPackOutputFilter

An endpoint filter that intercepts the handler's return value before System.Text.Json serializes it. When the client's Accept header includes application/x-msgpack, the value is serialized directly to MessagePack with no JSON intermediate. Results that carry no body (204, 404 without body, redirects) and problem-detail results (application/problem+json) are passed through unchanged.

<details> <summary><h3>Usage Examples</h3></summary>

WithMsgPackOutput

Attaches MsgPackOutputFilter to an endpoint or route group. Optionally accepts custom MessagePackSerializerOptions; defaults to MessagePackSerializer.DefaultOptions when null.

// Apply to a single endpoint
app.MapGet("/entities/{id}", (int id, IBaseDbContextActions<MyEntity, MyDbContext> db) =>
    GenericMinimalEndpoints.GetById(id, db))
    .WithMsgPackOutput();

// Apply to an entire route group
RouteGroupBuilder group = app.MapGroup("/entities").WithMsgPackOutput();
group.MapGet("/{id}", (int id) => Results.Ok(myEntity));

</details>


FlexibleDecimalResolver

FlexibleDecimalResolver is a MessagePack IFormatterResolver that intercepts decimal and decimal? serialization and substitutes FlexibleDecimalFormatter / FlexibleNullableDecimalFormatter in place of the built-in DecimalFormatter.

Why you need it: The standard DecimalFormatter only accepts the string msgpack encoding that C# produces. JavaScript clients using msgpackr always encode JS number values as msgpack integers or floats, never as strings. Without this resolver those payloads throw a deserialization exception.

  • FlexibleDecimalFormatter — handles decimal; deserializes from msgpack string, integer, or float.
  • FlexibleNullableDecimalFormatter — handles decimal?; additionally handles the msgpack nil token.
  • FlexibleDecimalResolver — resolver that routes decimal / decimal? to the two formatters above and returns null for everything else.

Register FlexibleDecimalResolver before StandardResolver (or any other resolver that handles decimals) in a CompositeResolver.

<details> <summary><h3>Usage Examples</h3></summary>

Registering with a CompositeResolver

Use this approach for minimal API applications or any scenario where you supply MessagePackSerializerOptions directly (e.g. to WithMsgPackOutput).

using MessagePack;
using MessagePack.Resolvers;
using CommonNetFuncs.Web.Api.MsgPack;

// Build options that accept both C# string-encoded decimals and JS numeric decimals.
MessagePackSerializerOptions options = MessagePackSerializerOptions.Standard
    .WithResolver(CompositeResolver.Create(
        FlexibleDecimalResolver.Instance,  // must come first
        StandardResolver.Instance));

// Pass to WithMsgPackOutput (optional – omit to use DefaultOptions)
app.MapGet("/entities/{id}", (int id) => Results.Ok(myEntity))
   .WithMsgPackOutput(options);

// Or set as the global default
MessagePackSerializer.DefaultOptions = options;
Registering with AddMvc / AddControllers

When using MVC controllers with the MessagePack-CSharp ASP.NET Core formatter, supply the options when adding the formatters.

using MessagePack;
using MessagePack.Resolvers;
using CommonNetFuncs.Web.Api.MsgPack;

MessagePackSerializerOptions options = MessagePackSerializerOptions.Standard
    .WithResolver(CompositeResolver.Create(
        FlexibleDecimalResolver.Instance,
        StandardResolver.Instance));

builder.Services.AddControllers()
    .AddMessagePackFormatters(o =>
    {
        o.SerializerOptions = options;
    });

Note: FlexibleDecimalResolver.Instance must appear before StandardResolver.Instance (or ContractlessStandardResolver.Instance) so that its decimal / decimal? registrations take precedence.

</details>


Installation

Install via NuGet:

dotnet add package CommonNetFuncs.Web.Api

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
4.1.7 77 6/23/2026
4.1.6 97 6/15/2026
4.1.4 101 6/10/2026
4.1.3 103 6/9/2026
4.1.2 116 6/6/2026
4.1.1 101 6/5/2026
4.1.0 108 6/5/2026
4.0.56 118 6/2/2026
4.0.53 119 5/28/2026
4.0.52 100 5/27/2026
4.0.48 110 5/19/2026
4.0.43 135 5/14/2026
4.0.40 110 5/10/2026
4.0.39 103 5/10/2026
4.0.37 103 5/9/2026
4.0.36 103 5/8/2026
4.0.34 116 4/28/2026
4.0.33 121 4/23/2026
4.0.31 113 4/21/2026
Loading failed