MinimalApis.Extensions icon indicating copy to clipboard operation
MinimalApis.Extensions copied to clipboard

Add example of APIs that return multiple result types in their signature

Open DamianEdwards opened this issue 3 years ago • 0 comments

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

DamianEdwards avatar Oct 06 '21 22:10 DamianEdwards