Loading...
Loading...
Defines REST endpoints using Minimal APIs with OpenAPI documentation via Scalar. Use when: Creating or modifying API endpoints in Sorcha services, adding new routes, configuring endpoint authentication, or documenting APIs.
npx skill4agent add stuartf303/sorcha minimal-apisMapGroup()Endpoints/// src/Services/Sorcha.Wallet.Service/Endpoints/WalletEndpoints.cs
public static IEndpointRouteBuilder MapWalletEndpoints(this IEndpointRouteBuilder app)
{
var walletGroup = app.MapGroup("/api/v1/wallets")
.WithTags("Wallets")
.RequireAuthorization("CanManageWallets");
walletGroup.MapPost("/", CreateWallet)
.WithName("CreateWallet")
.WithSummary("Create a new wallet")
.WithDescription("Creates a new HD wallet with the specified algorithm");
walletGroup.MapGet("/{address}", GetWallet)
.WithName("GetWallet")
.WithSummary("Get wallet by address");
return app;
}private static async Task<IResult> CreateWallet(
[FromBody] CreateWalletRequest request,
WalletManager walletManager,
HttpContext context,
ILogger<Program> logger,
CancellationToken cancellationToken = default)
{
try
{
var (wallet, mnemonic) = await walletManager.CreateWalletAsync(...);
return Results.Created($"/api/v1/wallets/{wallet.Address}", response);
}
catch (ArgumentException ex)
{
return Results.BadRequest(new ProblemDetails { Title = "Invalid Request", Detail = ex.Message });
}
}| Concept | Usage | Example |
|---|---|---|
| Route Groups | Shared config for related endpoints | |
| TypedResults | Type-safe return values | |
| OpenAPI Metadata | | Required on all endpoints |
| Authorization | | Apply to groups or individual endpoints |
| AllowAnonymous | Public endpoints | |
| Cache Output | Redis output caching | |
private static async Task<Results<Ok<TokenResponse>, UnauthorizedHttpResult, ValidationProblem>> Login(
LoginRequest request,
ITokenService tokenService)
{
if (string.IsNullOrWhiteSpace(request.Email))
return TypedResults.ValidationProblem(new Dictionary<string, string[]>
{
["email"] = ["Email is required"]
});
var token = await tokenService.LoginAsync(request);
if (token == null) return TypedResults.Unauthorized();
return TypedResults.Ok(token);
}walletGroup.MapGet("/{address}/addresses", ListAddresses);
private static async Task<IResult> ListAddresses(
string address, // Route parameter
[FromQuery] string? type = null, // Optional filter
[FromQuery] bool? used = null, // Optional filter
[FromQuery] int page = 1, // Default pagination
[FromQuery] int pageSize = 50)Fetch latest ASP.NET Core Minimal APIs documentation with Context7.
mcp__context7__resolve-library-id/websites/learn_microsoft_en-us_aspnet_coremcp__context7__query-docs/websites/learn_microsoft_en-us_aspnet_core