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
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,19 @@ description: Provides an overview of Minimal APIs in ASP.NET Core
5
5
ms.author: wpickett
6
6
content_well_notification: AI-contribution
7
7
monikerRange: '>= aspnetcore-6.0'
8
-
ms.date: 09/08/2025
8
+
ms.date: 10/23/2025
9
9
uid: fundamentals/minimal-apis
10
10
ai-usage: ai-assisted
11
11
---
12
12
13
-
<!-- When working on this file, open all the LATEST VERSION MD files in ~/fundamentals/minimal-apis/includes/ and search for the target text -->
13
+
<!--
14
+
Editorial note: This file is a quick reference summary:
15
+
- When working on this file, open all the LATEST VERSION MD files in ~/fundamentals/minimal-apis/includes/ and search for the target text.
16
+
- Only include brief overviews, essential lists, and basic examples in this file.
17
+
- Do NOT add detailed explanations, advanced scenarios, or troubleshooting—move those to dedicated include files (for example: parameter-binding8-10.md) and link to them from here if needed.
18
+
- All in-depth content should be placed in the appropriate in-depth include file for maintainability and clarity.
19
+
- Use H3 (###) for section headings within this include.
20
+
-->
14
21
15
22
# Minimal APIs quick reference
16
23
@@ -68,7 +75,7 @@ The <xref:System.Delegate> arguments passed to these methods are called "route h
Parameter binding is the process of converting request data into strongly typed parameters that are expressed by route handlers. A binding source determines where parameters are bound from. Binding sources can be explicit or inferred based on HTTP method and parameter type.
4
+
5
+
Supported binding sources:
6
+
7
+
* Route values
8
+
* Query string
9
+
* Header
10
+
* Body (as JSON)
11
+
* Form values
12
+
* Services provided by dependency injection
13
+
* Custom
14
+
15
+
The following GET route handler uses some of these parameter binding sources:
***Explicit binding**: Use attributes like `[FromRoute]`, `[FromQuery]`, `[FromHeader]`, `[FromBody]`, `[FromForm]`, and `[FromServices]` to explicitly specify binding sources.
22
+
***Form binding**: Bind form values using `[FromForm]` attribute, including support for `IFormFile` and `IFormFileCollection` for file uploads.
23
+
***Complex types**: Bind to collections and complex types from forms, query strings, and headers.
24
+
***Custom binding**: Implement custom binding logic using `TryParse`, `BindAsync`, or the `IBindableFromHttpContext<T>` interface.
25
+
***Optional parameters**: Support nullable types and default values for optional parameters.
26
+
***Dependency injection**: Parameters are automatically bound from services registered in the DI container.
27
+
***Special types**: Automatic binding for `HttpContext`, `HttpRequest`, `HttpResponse`, `CancellationToken`, `ClaimsPrincipal`, `Stream`, and `PipeReader`.
28
+
29
+
---
30
+
31
+
**Learn more:** For detailed information on parameter binding including advanced scenarios, validation, binding precedence, and troubleshooting, see <xref:fundamentals/minimal-apis/parameter-binding>.
Attributes can be used to explicitly declare where parameters are bound from.
41
41
@@ -49,7 +49,7 @@ Attributes can be used to explicitly declare where parameters are bound from.
49
49
|`service`| Provided by dependency injection |
50
50
|`contentType`| header with the name `"Content-Type"`|
51
51
52
-
####Explicit binding from form values
52
+
### Explicit binding from form values
53
53
54
54
The [`[FromForm]`](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute) attribute binds form values:
55
55
@@ -65,7 +65,7 @@ For more information, see the section on [AsParameters](#parameter-binding-for-a
65
65
66
66
The [complete sample code](https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/IFormFile) is in the [AspNetCore.Docs.Samples](https://github.com/dotnet/AspNetCore.Docs.Samples) repository.
67
67
68
-
####Secure binding from IFormFile and IFormFileCollection
68
+
### Secure binding from IFormFile and IFormFileCollection
69
69
70
70
Complex form binding is supported using <xref:Microsoft.AspNetCore.Http.IFormFile> and <xref:Microsoft.AspNetCore.Http.IFormFileCollection> using the [`[FromForm]`](xref:Microsoft.AspNetCore.Mvc.FromFormAttribute):
71
71
@@ -77,13 +77,13 @@ For more information, see [Form binding in minimal APIs](https://andrewlock.net/
77
77
78
78
The [complete sample code](https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/FormBinding) is in the [AspNetCore.Docs.Samples](https://github.com/dotnet/AspNetCore.Docs.Samples) repository.
79
79
80
-
###Parameter binding with dependency injection
80
+
## Parameter binding with dependency injection
81
81
82
82
Parameter binding for minimal APIs binds parameters through [dependency injection](xref:fundamentals/dependency-injection) when the type is configured as a service. It's not necessary to explicitly apply the [`[FromServices]`](xref:Microsoft.AspNetCore.Mvc.FromServicesAttribute) attribute to a parameter. In the following code, both actions return the time:
Parameters declared in route handlers are treated as required:
89
89
@@ -127,7 +127,7 @@ The preceding code calls the method with a null product if no request body is se
127
127
128
128
See the [Binding Failures](#bf) section for more information.
129
129
130
-
###Special types
130
+
## Special types
131
131
132
132
The following types are bound without explicit attributes:
133
133
@@ -159,7 +159,7 @@ The following types are bound without explicit attributes:
159
159
160
160
<aname="rbs"></a>
161
161
162
-
####Bind the request body as a `Stream` or `PipeReader`
162
+
### Bind the request body as a `Stream` or `PipeReader`
163
163
164
164
The request body can bind as a [`Stream`](/dotnet/api/system.io.stream) or [`PipeReader`](/dotnet/api/system.io.pipelines.pipereader) to efficiently support scenarios where the user has to process data and:
165
165
@@ -184,7 +184,7 @@ The following code shows the complete `Program.cs` file:
184
184
* The request body isn't buffered by default. After the body is read, it's not rewindable. The stream can't be read multiple times.
185
185
* The `Stream` and `PipeReader` aren't usable outside of the minimal action handler as the underlying buffers will be disposed or reused.
186
186
187
-
####File uploads using IFormFile and IFormFileCollection
187
+
### File uploads using IFormFile and IFormFileCollection
188
188
189
189
The following code uses <xref:Microsoft.AspNetCore.Http.IFormFile> and <xref:Microsoft.AspNetCore.Http.IFormFileCollection> to upload file:
190
190
@@ -194,7 +194,7 @@ Authenticated file upload requests are supported using an [Authorization header]
194
194
195
195
<aname="bind8"></a>
196
196
197
-
####Binding to forms with IFormCollection, IFormFile, and IFormFileCollection
197
+
### Binding to forms with IFormCollection, IFormFile, and IFormFileCollection
198
198
199
199
Binding from form-based parameters using <xref:Microsoft.AspNetCore.Http.IFormCollection>, <xref:Microsoft.AspNetCore.Http.IFormFile>, and <xref:Microsoft.AspNetCore.Http.IFormFileCollection> is supported. [OpenAPI](xref:fundamentals/openapi/aspnetcore-openapi) metadata is inferred for form parameters to support integration with [Swagger UI](xref:tutorials/web-api-help-pages-using-swagger).
200
200
@@ -212,7 +212,7 @@ For more information, see [Form binding in minimal APIs](https://andrewlock.net/
212
212
213
213
<aname="bindcc"></a>
214
214
215
-
###Bind to collections and complex types from forms
215
+
## Bind to collections and complex types from forms
216
216
217
217
Binding is supported for:
218
218
@@ -244,7 +244,7 @@ isCompleted: false
244
244
245
245
<aname="bindar"></a>
246
246
247
-
###Bind arrays and string values from headers and query strings
247
+
## Bind arrays and string values from headers and query strings
248
248
249
249
The following code demonstrates binding query strings to an array of primitive types, string arrays, and [StringValues](/dotnet/api/microsoft.extensions.primitives.stringvalues):
250
250
@@ -279,7 +279,7 @@ The following code binds to the header key `X-Todo-Id` and returns the `Todo` it
279
279
280
280
<aname="asparam7"></a>
281
281
282
-
###Parameter binding for argument lists with [AsParameters]
282
+
## Parameter binding for argument lists with [AsParameters]
283
283
284
284
<xref:Microsoft.AspNetCore.Http.AsParametersAttribute> enables simple parameter binding to types and not complex or recursive model binding.
285
285
@@ -319,15 +319,15 @@ Using a `struct` with `AsParameters` can be more performant than using a `record
319
319
320
320
The [complete sample code](https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/arg-lists) in the [AspNetCore.Docs.Samples](https://github.com/dotnet/AspNetCore.Docs.Samples) repository.
321
321
322
-
###Custom Binding
322
+
## Custom Binding
323
323
324
324
There are three ways to customize parameter binding:
325
325
326
326
1. For route, query, and header binding sources, bind custom types by adding a static `TryParse` method for the type.
327
327
1. Control the binding process by implementing a `BindAsync` method on a type.
328
328
1. For advanced scenarios, implement the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface to provide custom binding logic directly from the `HttpContext`.
329
329
330
-
####TryParse
330
+
### TryParse
331
331
332
332
`TryParse` has two APIs:
333
333
@@ -340,7 +340,7 @@ The following code displays `Point: 12.3, 10.1` with the URI `/map?Point=12.3,10
@@ -355,7 +355,7 @@ The following code displays `SortBy:xyz, SortDirection:Desc, CurrentPage:99` wit
355
355
356
356
<aname="bf"></a>
357
357
358
-
####Custom parameter binding with `IBindableFromHttpContext`
358
+
### Custom parameter binding with `IBindableFromHttpContext`
359
359
360
360
ASP.NET Core provides support for custom parameter binding in Minimal APIs using the <xref:Microsoft.AspNetCore.Http.IBindableFromHttpContext%601> interface. This interface, introduced with C# 11's static abstract members, allows you to create types that can be bound from an HTTP context directly in route handler parameters.
361
361
@@ -381,7 +381,7 @@ You can also implement validation within your custom binding logic:
381
381
382
382
[View or download the sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/10.0-samples/CustomBindingExample) ([how to download](xref:index#how-to-download-a-sample))
383
383
384
-
###Binding failures
384
+
## Binding failures
385
385
386
386
When binding fails, the framework logs a debug message and returns various status codes to the client depending on the failure mode.
387
387
@@ -393,7 +393,7 @@ When binding fails, the framework logs a debug message and returns various statu
393
393
| Failure to deserialize JSON body |doesn't matter|body|400|
394
394
| Wrong content type (not `application/json`) |doesn't matter|body|415|
395
395
396
-
###Binding Precedence
396
+
## Binding Precedence
397
397
398
398
The rules for determining a binding source from a parameter:
399
399
@@ -423,27 +423,27 @@ The rules for determining a binding source from a parameter:
423
423
1. If the parameter type is a service provided by dependency injection, it uses that service as the source.
424
424
1. The parameter is from the body.
425
425
426
-
###Configure JSON deserialization options for body binding
426
+
## Configure JSON deserialization options for body binding
427
427
428
428
The body binding source uses <xref:System.Text.Json?displayProperty=fullName> for deserialization. It is ***not*** possible to change this default, but JSON serialization and deserialization options can be configured.
Options that apply globally for an app can be configured by invoking <xref:Microsoft.Extensions.DependencyInjection.HttpJsonServiceExtensions.ConfigureHttpJsonOptions%2A>. The following example includes public fields and formats JSON output.
Since the sample code configures both serialization and deserialization, it can read `NameField` and include `NameField` in the output JSON.
437
437
438
-
####Configure JSON deserialization options for an endpoint
438
+
### Configure JSON deserialization options for an endpoint
439
439
440
440
<xref:Microsoft.AspNetCore.Http.HttpRequestJsonExtensions.ReadFromJsonAsync%2A> has overloads that accept a <xref:System.Text.Json.JsonSerializerOptions> object. The following example includes public fields and formats JSON output.
0 commit comments