-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Switch to Minimal API #896
Conversation
1be4557
to
a5576f9
Compare
Just some food for thought. |
Thanks @anguzo, I did look at Carter, but I wanted to align closely to ASP.NET Core Minimal API in the hopes that these or similar features will be added to ASP.NET Core. I've tried to keep the implementation very simple, without losing existing minimal API features. |
Overview
Minimal API is a new way of building ASP.NET Core apps. It allows developers to build web APIs by using just a few lines of code, with a focus on simplicity and ease of use. When using Minimal API, developers can define routes and handle requests without the use of controllers or actions. Instead, the whole app can be defined in a single file.
Minimal API does take a different approach to routing when compared to ASP.NET Core controllers. While traditional controllers rely on conventions and attribute-based routing, Minimal API requires explicit route configuration. I much prefer a convention-based approach, so in this implementation I've extended Minimal API to define routes based on class and method names. This has resulted in a simple and clean implementation of Minimal API within the template.
The original PR #720 includes more in-depth information for those interested in understanding the final design and additional insights related to the changes made. Thanks to everyone who contributed to that discussion. ✨
Changes Made
Example
Here's an example of how to use Minimal API within the template:
The above example demonstrates that groups of endpoints will be defined in a single file. The endpoint group name will be based on the class name
WeatherForecasts
and the endpoint name will be based on the method nameGetWeatherForecasts
. These names will be used for routing, tags, and within the Open API specification automatically.These classes (based on
EndpointGroupBase
) can be registered automatically withinProgram.cs
as follows:Feedback
Please review the changes and provide your feedback. Thank you! ❤️