TnTResult.AspNetCore.Http
1.1.17
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TnTResult.AspNetCore.Http --version 1.1.17
NuGet\Install-Package TnTResult.AspNetCore.Http -Version 1.1.17
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="TnTResult.AspNetCore.Http" Version="1.1.17" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TnTResult.AspNetCore.Http" Version="1.1.17" />
<PackageReference Include="TnTResult.AspNetCore.Http" />
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 TnTResult.AspNetCore.Http --version 1.1.17
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TnTResult.AspNetCore.Http, 1.1.17"
#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 TnTResult.AspNetCore.Http@1.1.17
#: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=TnTResult.AspNetCore.Http&version=1.1.17
#tool nuget:?package=TnTResult.AspNetCore.Http&version=1.1.17
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TnTResult Solution
TnTResult is a .NET solution providing a set of libraries for handling result types, error handling, and HTTP integration in C# applications. It is designed to improve code clarity, error propagation, and integration with ASP.NET Core and Refit-based APIs.
Table of Contents
Projects Overview
1. TnTResult
- Purpose:
- Core library for result types (
Expected
,Optional
, etc.), error handling, and utility extensions. - Provides a functional approach to handling success/failure and optional values.
- Core library for result types (
- Key Files:
Expected.cs
,Optional.cs
,TnTResult.cs
,TnTFileDownload.cs
- Extensions in
Ext/
- Custom exceptions in
Exceptions/
2. TnTResult.AspNetCore.Http
- Purpose:
- Integrates TnTResult types with ASP.NET Core HTTP pipeline.
- Provides helpers for controller responses and HTTP result mapping.
- Key Files:
ControllerRepositoryBase.cs
,HttpTnTResult.cs
- Extensions in
Ext/
3. TnTResult.Refit
- Purpose:
- Adds support for using TnTResult types with Refit (a REST library for .NET).
- Provides extension methods for working with
IApiResponse
and mapping API results.
- Key Files:
- Extensions in
Ext/
- Extensions in
4. TnTResult.Tests
- Purpose:
- Contains unit tests for all core and extension libraries.
- Organized by subproject and feature.
Build Instructions
Prerequisites:
- .NET 8.0 SDK or newer
- (Optional) Visual Studio 2022+ or VS Code
Restore dependencies:
dotnet restore TnTResult.sln
Build the solution:
dotnet build TnTResult.sln --configuration Release
Running Tests
All tests are located in the TnTResult.Tests
project. To run all tests:
dotnet test TnTResult.sln
Usage Examples
TnTResult
using TnTResult;
// --- Expected usage ---
var ok = Expected.MakeExpected<int, string>(42);
if (ok.HasValue)
{
Console.WriteLine($"Value: {ok.Value}");
}
else
{
Console.WriteLine($"Error: {ok.Error}");
}
var err = Expected.MakeUnexpected<int, string>("Something went wrong");
if (!err.HasValue)
{
Console.WriteLine($"Error: {err.Error}");
}
// --- Optional usage ---
var some = Optional.MakeOptional("hello");
if (some.HasValue)
{
Console.WriteLine($"Optional value: {some.Value}");
}
var none = Optional.NullOpt<string>();
if (none.IsEmpty)
{
Console.WriteLine("Optional is empty");
}
// --- ITnTResult usage ---
ITnTResult result = TnTResult.Successful;
result
.OnSuccess(() => Console.WriteLine("Operation succeeded!"))
.OnFailure(ex => Console.WriteLine($"Operation failed: {ex.Message}"))
.Finally(() => Console.WriteLine("Operation finished (success or failure)"));
// ITnTResult<T> usage
ITnTResult<string> result2 = TnTResult.Success("Hello");
result2
.OnSuccess(val => Console.WriteLine($"Success value: {val}"))
.OnFailure(ex => Console.WriteLine($"Failed: {ex.Message}"))
.Finally(() => Console.WriteLine("Done!"));
// --- Async usage with extension methods ---
using TnTResult.Ext;
await Task.FromResult(TnTResult.Successful)
.OnSuccessAsync(() => Console.WriteLine("Async success!"));
await Task.FromResult(TnTResult.Failure(new Exception("fail")))
.OnFailureAsync(ex => Console.WriteLine($"Async failure: {ex.Message}"));
TnTResult.AspNetCore.Http
using TnTResult.AspNetCore.Http;
using TnTResult;
using Microsoft.AspNetCore.Mvc;
// Inherit from TnTResultControllerBase to use static helpers
// Return ITnTResult from your actions—the base class will automatically convert it to an appropriate IResult for ASP.NET Core.
public class MyController : TnTResultControllerBase
{
[HttpGet("/created")]
public ITnTResult CreatedExample()
{
// Use the static SuccessfullyCreated property
return SuccessfullyCreated;
}
[HttpGet("/forbidden")]
public ITnTResult ForbiddenExample()
{
// Use the static FailureForbidden property
return FailureForbidden;
}
[HttpGet("/conflict")]
public ITnTResult ConflictExample()
{
// Use the static Conflict helper
return Conflict("A conflict occurred");
}
[HttpGet("/custom-created")]
public ITnTResult CustomCreatedExample()
{
// Use the static Created<T> helper for a custom value
return Created("Resource created!");
}
}
// Note: TnTResultControllerBase will automatically convert any ITnTResult returned from your action
// into the correct ASP.NET Core IResult (status code, body, etc.) for the HTTP response.
TnTResult.Refit
using TnTResult.Refit.Ext;
using Refit;
public interface IMyApi
{
[Get("/data")]
Task<IApiResponse<string>> GetDataAsync();
}
// Usage in your code:
var apiResponse = await myApi.GetDataAsync();
var result = apiResponse.ToTnTResult();
if (result.IsSuccess)
{
Console.WriteLine($"API value: {result.Value}");
}
else
{
Console.WriteLine($"API error: {result.Error.Message}");
}
License
This project is licensed under the MIT License. See LICENSE for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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 is compatible. 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. |
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 |
---|---|---|
1.1.22 | 207 | 9/8/2025 |
1.1.21 | 148 | 9/8/2025 |
1.1.20 | 187 | 8/29/2025 |
1.1.19 | 292 | 7/8/2025 |
1.1.18 | 161 | 6/4/2025 |
1.1.17 | 160 | 6/4/2025 |
1.1.16 | 164 | 6/4/2025 |
1.1.14 | 390 | 5/7/2025 |
1.1.13 | 175 | 4/29/2025 |
1.1.12 | 327 | 4/10/2025 |
1.1.11 | 184 | 4/2/2025 |
1.1.10 | 203 | 3/28/2025 |
1.1.9 | 487 | 3/24/2025 |
1.1.8 | 175 | 3/18/2025 |
1.1.7 | 170 | 3/18/2025 |
1.1.6 | 165 | 3/18/2025 |
1.1.5 | 167 | 3/18/2025 |
1.1.4 | 238 | 3/6/2025 |
1.1.3 | 242 | 3/5/2025 |
1.1.2 | 231 | 3/5/2025 |
1.1.1 | 149 | 2/14/2025 |
1.0.3 | 332 | 1/9/2025 |
1.0.1 | 113 | 1/8/2025 |