.NET 10 Minimal APIs Just Leveled Up with Built-In Validation
Stop Writing Boilerplate: Automatic Request Validation Has Arrived
Minimal APIs have always been about simplicity but validation has been one of the pain points… until now.
With .NET 10, Microsoft introduces native request validation for Minimal APIs, eliminating the need for repetitive checks and bringing them closer to the robustness of traditional controllers.
Let’s break down what’s new, why it matters, and how to use it in real-world code.
What’s New in .NET 10?
In previous versions, validation in Minimal APIs required manual checks like:
if (!MiniValidator.TryValidate(model, out var errors))
{
return Results.ValidationProblem(errors);
}Or using external libraries.
👉 In .NET 10, validation is now:
Built into the framework
Automatically executed before your endpoint logic
Based on standard Data Annotations
Returning consistent error responses
Step 1: Enable Validation
You only need one line to activate validation globally:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddValidation(); // New in .NET 10
var app = builder.Build();That’s it. No filters. No middleware. No manual wiring.
Step 2: Define Your Request Model
Use familiar Data Annotations:
using System.ComponentModel.DataAnnotations;
public record CreateProductRequest(
[Required] string Name,
[Range(1, 10)] decimal Price,
[Required] string Category
);Supported annotations include:
[Required][Range][MinLength][MaxLength][EmailAddress]and more...
Step 3: Create a Minimal API Endpoint
Now define your endpoint as usual:
app.MapPost(”/products”, (CreateProductRequest request) =>
{
// This runs ONLY if validation passes
return Results.Ok(new
{
Message = “Product created successfully”,
Data = request
});
});No validation logic required. Clean and focused.
What Happens on Invalid Requests?
If validation fails, ASP.NET Core automatically returns a standardized response:
Example Request:
{
“name”: “Laptop”,
“price”: 50,
“category”: “”
}Response:
{
“title”: “One or more validation errors occurred.”,
“errors”: {
“Price”: [
“The field Price must be between 1 and 10.”
],
“Category”: [
“The Category field is required.”
]
}
}👉 Your endpoint is never executed.
Full Working Example
Here’s a complete Program.cs:
using System.ComponentModel.DataAnnotations;
var builder = WebApplication.CreateBuilder(args);
// Enable validation
builder.Services.AddValidation();
var app = builder.Build();
// Request model
public record CreateProductRequest(
[Required] string Name,
[Range(1, 10)] decimal Price,
[Required] string Category
);
// Endpoint
app.MapPost(”/products”, (CreateProductRequest request) =>
{
return Results.Ok(new
{
Message = “Product created successfully”,
Product = request
});
});
app.Run();Minimal APIs vs Controllers
For a long time, controllers had a clear advantage: built-in validation.
That gap is now gone.
Automatic Validation
Before .NET 10
❌ Not available in Minimal APIs
You had to manually validate every request or use external libraries.
With .NET 10
✅ Built-in and automatic
Validation runs before your endpoint logic executes.
Clean Endpoints
Before .NET 10
⚠️ Often cluttered with validation checks
Your business logic was mixed with validation code.
With .NET 10
✅ Clean and focused
Endpoints now contain only business logic — no extra noise.
Consistency
Before .NET 10
❌ Inconsistent validation responses
Different endpoints could return different error formats.
With .NET 10
✅ Standardized responses
All validation errors follow a unified structure automatically.
Pro Tips
Combine with FluentValidation for advanced scenarios
Keep request models small and focused
Use custom attributes for reusable rules
Log validation failures for debugging insights
Final Thoughts
.NET 10 doesn’t just improve Minimal APIs —
it removes one of their biggest limitations.
You now get:
Clean code
Built-in validation
Consistent behavior
Less mental overhead
All with one line of configuration.
What Do You Think?
Have you tried this feature yet?
Do you still prefer controllers, or are Minimal APIs now your go-to?
I hope you found this guide helpful and informative.
Thanks for reading!
If you enjoyed this article, feel free to share it and follow me for more practical, developer-friendly content like this.

