.NET

Minimal APIs

Route handlers, parameter binding, filters, OpenAPI, route groups, performance

18 câu hỏi phỏng vấn·
Mid-Level
1

What is a Minimal API in ASP.NET Core?

Câu trả lời

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.

2

Which method allows defining a GET endpoint in Minimal APIs?

Câu trả lời

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.

3

How to bind a route parameter in a Minimal API endpoint?

Câu trả lời

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.

4

What is the difference between Results and TypedResults in Minimal APIs?

5

How to inject a service into a Minimal API handler?

+15 câu hỏi phỏng vấn

Nắm vững .NET cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí