Maple.Result.Extensions.MinimalApi
0.2.10
See the version list below for details.
dotnet add package Maple.Result.Extensions.MinimalApi --version 0.2.10
NuGet\Install-Package Maple.Result.Extensions.MinimalApi -Version 0.2.10
<PackageReference Include="Maple.Result.Extensions.MinimalApi" Version="0.2.10" />
<PackageVersion Include="Maple.Result.Extensions.MinimalApi" Version="0.2.10" />
<PackageReference Include="Maple.Result.Extensions.MinimalApi" />
paket add Maple.Result.Extensions.MinimalApi --version 0.2.10
#r "nuget: Maple.Result.Extensions.MinimalApi, 0.2.10"
#:package Maple.Result.Extensions.MinimalApi@0.2.10
#addin nuget:?package=Maple.Result.Extensions.MinimalApi&version=0.2.10
#tool nuget:?package=Maple.Result.Extensions.MinimalApi&version=0.2.10
Maple.Result.Extensions.MinimalApi
Maps the Maple.Result to the HTTP response (.NET Minimal API version)
Project status: EARLY STAGE
Check also my libraries:
- Maple.Result,
- Maple.Result.Extensions.AspNetCore,
- <i>Maple.Result.Extensions.Functions.Worker</i> (coming soon),
- Maple.Result.Extensions.HttpClient.
Give it a star ⭐
Do you like it? Show your support by giving this project a star!
Status
✅ Basic mapping without configuration.
✅ Unit and integration tests.
✅ Custom error mapping passed as a parameter to the extension method.
✅ Support for custom successful status codes.
🔲 Documentation.
Usage
using Maple.Result.Extensions.MinimalApi;
// Success -> 204 No Content, error -> RFC 9457 problem details
app.MapDelete("orders/{id}", (int id) => orderService.Delete(id).ToMinimalApiResult());
// Success -> 200 OK with the value (204 No Content when the value is null)
app.MapGet("orders/{id}", (int id) => orderService.Get(id).ToMinimalApiResult());
// Success -> the given status code
app.MapPost("orders", (Order order) => orderService.Create(order).ToMinimalApiResult(StatusCodes.Status201Created));
// Success -> mapped explicitly, e.g. to return the Location header
app.MapPost("orders", (Order order) => orderService.Create(order)
.ToMinimalApiResult(created => Results.Created($"orders/{created.Id}", created)));
// Errors -> mapped explicitly; the default mapping is used when the mapping returns null
app.MapGet("orders", () => orderService.GetAll().ToMinimalApiResult(
error => error.Category == ErrorCategory.Conflict ? Results.StatusCode(StatusCodes.Status410Gone) : null));
Example Error Response
Example
{
"type": "https://example.com/probs/out-of-credit",
"title": "You do not have enough credit.",
"status": 400,
"detail": "Your current balance is 30, but that costs 50.",
"instance": "/accounts/12345/msgs/abc",
"errors": [
{
"pointer": "#/age",
"detail": "must be a positive integer",
"detailTemplated": {
"templateId": "user.details.age.mustBePositive"
}
},
{
"pointer": "#/profile/colour",
"detail": "must be ‘green’, ‘red’ or ‘blue’",
"detailTemplated": {
"templateId": "user.profile.colour",
"params": {
"validValueIds": [
"user.profile.colour.green",
"user.profile.colour.red",
"user.profile.colour.blue"
]
}
}
}
],
"detailTemplated": {
"templateId": "user.account.balance.tooLow",
"params": {
"errorCode": "UAB17",
"accounts": [
{
"title": "Main (***9456)",
"url": "/accounts/12345"
},
{
"title": "Main (***3357)",
"url": "/accounts/67890"
}
],
"currentBalance": 30,
"requiredBalance": 50
}
}
}
The response also contains the traceId extension added by ASP.NET Core.
See also
- Problem Details for HTTP APIs - RFC 7807 is dead, long live RFC 9457
- tag URI scheme
- RFC 1738: Uniform Resource Locators (URL)
- RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
- RFC 4151: The 'tag' URI Scheme
- RFC 6901: JavaScript Object Notation (JSON) Pointer
- RFC 9457: Problem Details for HTTP APIs
Contribution
Please contact author: engineer(at sign)blumail(dot)me
| Product | Versions 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. |
-
net10.0
- Maple.Result (>= 2.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.