MinimalApis.Extensions
MinimalApis.Extensions copied to clipboard
Add example of APIs that return multiple result types in their signature
Essentially discriminated union results which can then be used to drive metadata for ApiExplorer
and Swagger.
app.MapPost("/todos", async Task<Results<Ok<Todo>, BadRequest>> (Todo todo) =>
{
if (!string.IsNullOrEmpty(todo.Title))
{
await Task.Yield();
return Results.Ok(todo);
}
return Results.BadRequest();
});
See https://gist.github.com/DamianEdwards/d98088016ec393ed201feb9c6e5b1d02