Nestgrid.Response
0.8.0
dotnet add package Nestgrid.Response --version 0.8.0
NuGet\Install-Package Nestgrid.Response -Version 0.8.0
<PackageReference Include="Nestgrid.Response" Version="0.8.0" />
<PackageVersion Include="Nestgrid.Response" Version="0.8.0" />
<PackageReference Include="Nestgrid.Response" />
paket add Nestgrid.Response --version 0.8.0
#r "nuget: Nestgrid.Response, 0.8.0"
#:package Nestgrid.Response@0.8.0
#addin nuget:?package=Nestgrid.Response&version=0.8.0
#tool nuget:?package=Nestgrid.Response&version=0.8.0
Nestgrid.Response
Framework-independent Result pattern primitives for .NET applications.
Nestgrid.Response provides immutable Result and Result<T> types for returning expected operation outcomes without throwing exceptions for routine control flow or coupling application logic to HTTP.
Installation
dotnet add package Nestgrid.Response
Quick Start
using Nestgrid.Response;
public Result<UserDto> FindUser(int id)
{
var user = users.Find(id);
return user is null
? Results.NotFound<UserDto>("User was not found.")
: Results.Ok(new UserDto(user.Id, user.Name));
}
Realistic Example
using Nestgrid.Response;
using Nestgrid.Response.Extensions;
public Result<UserDto> RenameUser(int id, string name)
{
if (string.IsNullOrWhiteSpace(name))
{
return Results.Invalid<UserDto>(
ResultMessages.Warning(
"Name is required.",
code: "name_required",
property: nameof(name)));
}
var user = users.Find(id);
if (user is null)
{
return Results.NotFound<UserDto>("User was not found.");
}
user.Rename(name);
return Results.Ok(user)
.Map(value => new UserDto(value!.Id, value.Name));
}
Feature Summary
- Immutable
ResultandResult<T>models. - Semantic statuses such as
Ok,Invalid,NotFound,Conflict,Failed, andError. Resultsfactory methods for successful and non-success outcomes.- Structured
ResultMessagevalues with severity, code, property and message text. ResultMessagesfactory methods for information, warning and error messages.IsSuccess(),IsFailure(),Map(), andMatch()extensions.- JSON serialization that omits
Result.Statusfrom payloads by default. - Generic no-content results through
Results.NoContent<T>().
Result Messages
Create messages with ResultMessages.Info, ResultMessages.Warning, or ResultMessages.Error:
var message = ResultMessages.Error(
"Name is required.",
code: "name_required",
property: "Name");
Messages are exposed as a read-only snapshot through Result.Messages.
Status Values
| Status | Meaning |
|---|---|
Ok |
Completed successfully |
Created |
Completed and created a resource |
Accepted |
Accepted for processing |
NoContent |
Completed without content |
Invalid |
Supplied input was invalid |
NotFound |
Requested resource was not found |
Unauthorized |
Caller is not authenticated |
Forbidden |
Caller is not permitted |
Conflict |
Conflicts with the current state |
Cancelled |
Operation was cancelled |
Failed |
Failed for an expected reason |
Error |
Failed because of an unexpected error |
Statuses are semantic application outcomes. Presentation packages decide how to map them to HTTP.
Functional Extensions
Import the extension namespace:
using Nestgrid.Response.Extensions;
IsSuccess() returns true for Ok, Created, Accepted, and NoContent. IsFailure() returns true for all other statuses.
Map() transforms the value of a successful Result<T> while preserving the original status and messages:
Result<UserDto> dto = user.Map(value =>
new UserDto(value!.Id, value.Name));
Match() branches on the same fixed success classification:
var displayName = dto.Match(
success => success?.Name ?? "Unknown",
failure => $"Could not load user: {failure.Status}");
Use Result.Status directly when code needs to distinguish specific outcomes.
Error(Exception)
Results.Error(Exception) converts an exception into an error result:
try
{
await service.RunAsync();
return Results.Ok();
}
catch (Exception exception)
{
logger.LogError(exception, "The operation failed.");
return Results.Error(exception);
}
The exception itself is not retained and diagnostic details are not copied into the normal result:
return Results.Error(exception);
This returns the client-safe message An unexpected error occurred. with no exception-derived code. Log the exception separately. This safe default is an intentional behaviour correction in v0.7.0; callers must not depend on the previous raw message or type-name output.
For trusted internal diagnostics only, use the explicitly named methods:
var diagnostic = Results.ErrorWithDiagnosticDetails(exception);
var typedDiagnostic = Results.ErrorWithDiagnosticDetails<UserDto>(exception);
These methods preserve the exception message and type name. Do not return their results directly to untrusted clients or serialise them without an explicit output policy.
NoContent<T>
Results.NoContent<T>() supports strongly typed service signatures that can complete without returning a value:
Task<Result<UserDto>> GetAsync(int id)
{
return Task.FromResult(Results.NoContent<UserDto>());
}
HTTP adapters treat ResultStatus.NoContent as a bodyless response.
Documentation
Samples
| Product | Versions 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. |
-
.NETStandard 2.0
- System.Text.Encodings.Web (>= 4.7.2)
- System.Text.Json (>= 4.6.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Nestgrid.Response:
| Package | Downloads |
|---|---|
|
Nestgrid.Response.Http
Shared HTTP response mapping policy for Nestgrid.Response adapters. |
|
|
Nestgrid.Response.Extensions.Validation
Data annotations validation extensions for Nestgrid.Response. |
|
|
Nestgrid.Response.Http.Client
Explicit HTTP response interpretation for Nestgrid.Response results. |
GitHub repositories
This package is not used by any popular GitHub repositories.