Design validation for Minimal APIs
See original GitHub issueIdea:
// Step 5: Input validation
app.MapPost("/todos", async (Validated<Todo> inputTodo, TodoDb db) =>
{
var (todo, isValid) = inputTodo;
if (!isValid) return Problem(inputTodo);
db.Todos.Add(todo);
await db.SaveChangesAsync();
return CreatedAt(routes.GetTodo.Url(todo.Id), todo);
};
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:22 (22 by maintainers)
Top Results From Across the Web
Minimal API Validation with FluentValidation
DependencyInjectionExtensions . This package holds the extension methods that allow you to register all validators in a Minimal APIs web ...
Read more >Use model validation in minimal APIs in ASP.NET Core 6
There is no built-in support for model validation in minimal APIs (unlike in ASP.NET Core MVC and Razor Pages). Hence, you will need...
Read more >FluentValidation in minimal APIs in ASP.NET Core 7.0
In this article, we will learn how to implement FluentValidation to our model classes in ASP.NET core 7 with minimal APIs.
Read more >Using ASP.NET Core 7 Minimal APIs: Request Filters ... - InfoQ
Minimal APIs can use bespoke middleware that allows validation of the request and the capability to execute code before or after processing ...
Read more >Tutorial: Create a minimal API with ASP.NET Core
Learn how to build a minimal API with ASP.NET Core.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

In .NET 7 you’ll be able to write a filter that can run validation on all the parameters trivially. In fact @DamianEdwards, you should add that filter to the Minimal.Extensions.
MVC already has a validation system so we wouldn’t change it. It does what it does. As for minimal APIs, doing it by default means we need to have an abstraction so others can plug in (for things like fluent validation etc) or a way to turn it off. The way I see it the extensibility point for plugging in validation is filters, so you can plug in to do it automagically.
Doing some “customer research” https://twitter.com/DamianEdwards/status/1486871181252833284
Result: