.NET

Minimal APIs

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

18 gespreksvragen·
Mid-Level
1

What is a Minimal API in ASP.NET Core?

Antwoord

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?

Antwoord

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?

Antwoord

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 gespreksvragen

Beheers .NET voor je volgende gesprek

Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.

Begin gratis