You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/minimal-apis.md
+8-23Lines changed: 8 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,14 @@ Support for validation in Minimal APIs is now available. This feature allows you
78
78
* Header
79
79
* Request body
80
80
81
-
Validations are defined using attributes in the [`DataAnnotations`](xref:System.ComponentModel.DataAnnotations) namespace. Developers customize the behavior of the validation system by:
81
+
Validations are defined using attributes in the [`DataAnnotations`](xref:System.ComponentModel.DataAnnotations) namespace.
82
+
83
+
When a parameter to a Minimal API endpoint is a class or record type, validation attributes are automatically applied. For example:
Minimal APIs also support validation with C# record types. Record types can be validated using attributes from the <xref:System.ComponentModel.DataAnnotations?displayProperty=fullName> namespace, similar to classes. For example:
112
-
113
-
```csharp
114
-
publicrecordProduct(
115
-
[Required] stringName,
116
-
[Range(1, 1000)] intQuantity);
117
-
```
118
-
119
-
When using record types as parameters in Minimal API endpoints, validation attributes are automatically applied in the same way as class types:
120
-
121
-
```csharp
122
-
app.MapPost("/products", (Productproduct) =>
123
-
{
124
-
// Endpoint logic here
125
-
returnTypedResults.Ok(product);
126
-
});
127
-
```
128
-
129
114
## Responses
130
115
131
116
Route handlers support the following types of return values:
0 commit comments