Skip to content

So how do you set up a Minimal API with .NET 6?

So let’s get this started. As many of you already know .NET 6 was released and with it, we have some really new cool features among those we have Minimal APIs.

When you just want a single endpoint API, setting up that on .NET would have lots of overhead, and compared to the single file server from Node.JS the choice would be easy to do.

The Minimal Apis came to solve exactly this issue, basically, this will allow us to create micro APIs without all this overhead that we are all aware of. As a Microsoft fanboy, this makes me very happy because I believe that this will have a very good adoption from the community.

So how do you set up a Minimal Api with .NET 6?

Obviously, the first thing you need to do is to install the .NET 6 SDK.

After installing the SDK ensure that your .NET version is the latest one since previous versions won’t have this new feature.

$ dotnet --version

At this moment you have everything you need to create your first Minimal API. You just have to run the command:

$ dotnet new web -o MinApi

This command will create a Minimal API where the Program.cs file looks like this:

Of course, this simple API doesn’t have DI, logic, multiple endpoints, and all sorts of more complex stuff that we usually need but who said that it couldn’t have? All these are still available for you to use if you need to.

At this moment you’re thinking that this is too simple and too easy, and you’re right! It really is that simple and that’s, in my opinion, the big value proposition here.

The possibility to have everything working out in a very simple and straightforward way like many other lightweight web frameworks such as Node.JS will be game-changing for many Engineers when they have to choose the technology for very simple APIs.

It’s is really nice to see how .NET is evolving and the power it gets on every iteration. We Microsoft fanboys just want to see .NET take over the world and it is a bit closer to that with .NET 6.

I hope you guys enjoyed this article and take some time to try it for yourselves and see how amazing and simple this is.

Keep coding!

Leave a Reply

Your email address will not be published. Required fields are marked *