Bogdan Bujdea
Bogdan Bujdea

Bogdan Bujdea

My experience with .NET 6 Minimal APIs

I wish we had Minimal APIs since day 1 of ASP.NET

Bogdan Bujdea
·Apr 28, 2022·

3 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • Resources
  • Switching to a real-world application
  • Why we picked classic controllers instead of Minimal APIs?
  • Conclusion

A few weeks ago I had to develop a PoC which also involved a small backend. I thought this would be a good idea to try Minimal APIs, and based on this experience we would decide whether they are a good fit for us or not.

Resources

I think there are plenty of articles and videos about Minimal APIs out there, most of them free, but I wanted something more than a "Hello World!", so I bought this course from Nick Chapsas. In less than one hour I had enough information to start the project and also see what are the best practices when using Minimal APIs. In this course, Nick covered a lot of useful concepts and how to implement them in Minimal APIs, things like:

  • Routing
  • Parameter binding
  • Configuring services and middleware
  • Using a database
  • Structuring Minimal APIs
  • etc.

This was enough for me to finish the PoC without wasting time googling for "how to do X with Minimal APIs", everything I needed was there! That being said, I really enjoyed writing my minimal API. I did end up with a Program.cs file that had ~300 lines of code and no unit tests... but in my defense this was just a PoC 😅

Switching to a real-world application

A few days ago we decided that the PoC was a success and we had to rewrite it, but first we had a long discussion about the architecture of the app. One of the points discussed was if we should go along with Minimal APIs or use classic controllers. After a short debate we decided to use classic controllers.

Why we picked classic controllers instead of Minimal APIs?

Features

I initially named this "Lack of features" but it sounded too harsh and it's not really the case. There are still some things missing from Minimal APIs (most of them will come in .NET 7), but you might not need them at all. Nevertheless, I know how it is to be blocked by issues from the platform you're developing on (hello Xamarin.Forms), so I really want to avoid this, that's why this was one of the major reasons we went with classic controllers.

Not a good fit for us

Our API will be big, lots of endpoints and that's why I know for sure I'm not going to put all of this into Program.cs Sure, I can create files with endpoints, but that looks an awful lot like controllers, right? That's why we'll just use classic controllers from the start.

Conclusion

I love Minimal APIs and I think they are great for micro-services, POCs, or serving as a starting point for developers who want to learn ASP.NET. However, for us it wasn't the right fit, so we decided to ditch them in favor of the classic controllers because we want to use the greatest and latest but we also want to be fully featured.

Did you find this article valuable?

Support Bogdan Bujdea by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this