Knight.Response.Abstractions.Http 2.0.0-preview02

This is a prerelease version of Knight.Response.Abstractions.Http.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Knight.Response.Abstractions.Http --version 2.0.0-preview02
                    
NuGet\Install-Package Knight.Response.Abstractions.Http -Version 2.0.0-preview02
                    
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="Knight.Response.Abstractions.Http" Version="2.0.0-preview02" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Knight.Response.Abstractions.Http" Version="2.0.0-preview02" />
                    
Directory.Packages.props
<PackageReference Include="Knight.Response.Abstractions.Http" />
                    
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 Knight.Response.Abstractions.Http --version 2.0.0-preview02
                    
#r "nuget: Knight.Response.Abstractions.Http, 2.0.0-preview02"
                    
#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 Knight.Response.Abstractions.Http@2.0.0-preview02
                    
#: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=Knight.Response.Abstractions.Http&version=2.0.0-preview02&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Knight.Response.Abstractions.Http&version=2.0.0-preview02&prerelease
                    
Install as a Cake Tool

Knight.Response.Abstractions.Http

Cross‑framework abstractions for HTTP result handling in the Knight.Response family.

This package collects the shared contracts, options, and resolvers that both

  • Knight.Response.AspNetCore (for modern ASP.NET Core / minimal APIs), and
  • Knight.Response.AspNetCore.Mvc (for legacy ASP.NET Core MVC 2.x / .NET Framework scenarios)

use to keep behavior consistent.

NuGet Version ci Mutation score

Target frameworks: .NET Standard 2.0 (works with .NET Framework 4.7.1+ and .NET Core/.NET 6+).


What’s inside

  • KnightResponseBaseOptions<TH, TProblem, TValidation> Base options class that centralizes:

    • UseProblemDetails (default: false)
    • UseValidationProblemDetails (default: false)
    • IncludeFullResultPayload (default: false, was true before 2.0.0-preview01)
    • IncludeExceptionDetails (default: false)
    • CodeToHttp delegate (optional, domain codes → HTTP codes)
    • StatusCodeResolver delegate (defaults to 400/409/500/200)
    • Optional builders/hooks for shaping problem responses

    The generic parameters let each integration plug in the framework’s own HttpContext type (TH), ProblemDetails type (TProblem), and ValidationProblemDetails type (TValidation) without duplication.

  • HTTP mapping defaults and resolvers

    • KnightResponseHttpDefaults — default mapping from Status to HTTP codes.
    • ResultHttpResolver — unified logic for resolving an HTTP code from a Result, honoring CodeToHttp first and falling back to StatusCodeResolver.
  • Validation error mapping

    • IValidationErrorMapper — abstraction for converting domain Messages into a Dictionary<string,string[]> suitable for validation problems.
    • DefaultValidationErrorMapper — conservative default implementation.
    • Consumers can register their own mapper in DI. If none is provided, integrations will fall back to the default.

Install

dotnet add package Knight.Response.Abstractions.Http

You typically won’t reference this directly in application code; it’s a transitive dependency of the ASP.NET/MVC integration packages. It’s useful if you’re building your own integration and want to align with Knight.Response conventions.


Quick examples

Custom validation mapper

using Knight.Response.Abstractions.Http.Mappers;

public sealed class MyValidationMapper : IValidationErrorMapper
{
    public IDictionary<string, string[]> Map(IReadOnlyList<Message> messages)
        => new Dictionary<string, string[]> { ["name"] = new[] { "is required" } };
}

Register this type in the DI container of your chosen integration package (e.g., Knight.Response.AspNetCore or Knight.Response.Mvc).

Custom HTTP code mapping

using Knight.Response.Models;
using Knight.Response.Abstractions.Http.Options;

services.AddKnightResponse(opts =>
{
    opts.CodeToHttp = code => code?.Value switch
    {
        var v when v == ResultCodes.NotFound.Value     => 404,
        var v when v == ResultCodes.AlreadyExists.Value => 409,
        _ => null
    };
});

  • Knight.Response — immutable Result / Result<T> core library.
  • Knight.Response.AspNetCore — modern ASP.NET Core + minimal APIs integration.
  • Knight.Response.AspNetCore.Mvc — ASP.NET Core MVC 2.x / .NET Framework–friendly integration.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Knight.Response.Abstractions.Http:

Package Downloads
Knight.Response.Mvc

ASP.NET MVC / Web API 2 adapters for Knight.Response — convert Result/Result<T> to IActionResult/IHttpActionResult with optional RFC7807 ProblemDetails.

Knight.Response.AspNetCore

ASP.NET Core helpers for Knight.Response: map Result/Result<T> to IResult/ActionResult with consistent HTTP semantics.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview03 138 9/27/2025
2.0.0-preview02 223 9/25/2025
2.0.0-preview01 318 9/24/2025
1.0.2 511 9/1/2025
1.0.1 262 8/28/2025
1.0.0 182 8/28/2025

- Added ResultHttpResolver with unified CodeToHttp/Status fallback.
           - Introduced KnightResponseHttpDefaults with Status→HTTP defaults.
           - CodeToHttp delegate now optional and consumer-configurable.