
Minimal APIs
Route handlers, parameter binding, filters, OpenAPI, route groups, performance
1What is a Minimal API in ASP.NET Core?
What is a Minimal API in ASP.NET Core?
답변
Minimal APIs are a simplified approach to creating HTTP APIs in ASP.NET Core, introduced with .NET 6. They allow defining endpoints directly in Program.cs without requiring controllers or complex configuration. This approach reduces boilerplate code and improves performance for simple to moderately complex APIs, while offering a more modern and functional development experience.
2Which method allows defining a GET endpoint in Minimal APIs?
Which method allows defining a GET endpoint in Minimal APIs?
답변
MapGet is the dedicated method for registering an HTTP GET endpoint in Minimal APIs. It takes as parameters the route pattern and a delegate that defines the processing logic. This method is part of the Map* method family which also includes MapPost, MapPut, MapDelete, and MapPatch for other HTTP verbs.
3How to bind a route parameter in a Minimal API endpoint?
How to bind a route parameter in a Minimal API endpoint?
답변
Route parameter binding in Minimal APIs is done automatically by naming convention. Simply define a parameter in the route pattern between curly braces, then declare a parameter with the same name in the handler signature. ASP.NET Core automatically performs the binding and type conversion. For example, for a pattern /users/{id}, an int id parameter will be automatically bound and converted.
What is the difference between Results and TypedResults in Minimal APIs?
How to inject a service into a Minimal API handler?
+15 면접 질문