Should I Create A Minimal API Or Full API?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to this episode of Dev questions with Tim Corey join us as we tackle the questions you are asking about a career in software development understanding the industry and new technology if you are just starting out or you want to grow stronger as a developer this is the place to get your questions answered now here's your host expert developer and online educator Tim Corey should I create a minimal API or a full API that's the question for today's episode of Dev questions now if you have a question you'd like to see answered go to suggestions.imcorey.com now this questions come up a lot recently because of the work I've done on my YouTube channel on minimal apis and so the question is why do we use minimal apis we already have an API structure what's the difference what's what's the point of them and the simple answer is that it's up to you when you use minimal apis versus full apis think of it like having two different screwdrivers that are maybe a little different size but they're the same type well why'd you have two well because one might fit your situation A little better and so having to give you options it gives you a choice in the matter the original purpose of a minimal API was micro Services the idea that we could write a very very small API there's no reason then to have a separate controller file and separate model file and separate all the stuff out when it could all really be in one page and be simpler or a small API or maybe you have one controller but four or five actions on that well that'd be a good choice for a minimal API instead where again maybe it's still one file separate out but it's just one you know or five endpoints that's kind of simple but let's talk now about you know some of you are already thinking your mind I'm pushed back on the idea well but controllers are there for a reason we have controllers and they're a good pattern let's talk about design patterns from it because often design patterns are misunderstood and yes this is relevant to apis because the API has this this pattern of creating controllers and separating controllers out from the models and separating that out from the the startup logic and having all the separation but what's the point of a pattern a pattern's goal is to ease maintainability and it's to ease readability so it makes it easier to read and makes it easier to maintain and if you think through the different design patterns that you know about it feels like they don't do that it feels like they make things more complex and the reason why is because you're applying them too early the goal is that you apply something that may be somewhat complex because your code is more complex or will be more complex and so this pattern might be complex but it's easier and easier to maintain and easier to read than the alternative but when the alternative is simpler guess what you shouldn't apply that pattern I I have an example on YouTube where I create the perfect console application they have a big asterisk on the screen because it's a it's a lot of code and it's give good code and it's code that in the right situation is awesome but the end result is it's an application that says hello world did it need to be multiple files and different depends the injection and all the rest of this good stuff logging didn't need to have all this stuff well no because it was just going to say console.writeline hello world that's it well that's the kind of Point here is when you have something so simple you don't need to add a pattern to you don't need to separate out files you don't need to have the complexity because it's so simple and that's where again micro services and small apis can benefit from this minimal API pattern or middle API structure because it is much simpler and much less patterns or cruft around the code so it's much more just here's the code here's you know here's a startup code and then down here is you know the actual API code three or four five endpoints and that's it well that can be a one file and it's okay so microservices small apis really benefit from the idea of minimal apis now if you structure them properly larger apis can also benefit from minimal API design again minimal apis are designed to be just what you need and simple to read and simple to use again easy to maintain and readable well even with a growing structure of your API you can still add out and add more things but not have to go to the controller model because maybe it's not the right call for your specific situation you can grow out a minimal API that is still clean even after you have 30 and 40 different endpoints so there are ways of doing it and ways to grow a minimal API to a pretty large size and ways to make a controller-based API smaller so there's a lot of overlap here which is why again I come back to it kind of depends on what you want to do you get the choice of what you think is best for your situation for your code base and for your developers now there is no need to convert controllers over to endpoints you don't have to do that leave them it's just a different tool you can have more than one tool in your toolbox don't just always look for the best tool look for the tool that works best for your particular situation and the next time a situation comes up evaluate again if you did want to update fine cool that's up to you and it may work well if you're looking to go from say.net framework API over to a.net 7 API so you can upgrade if you want or change if you want but really choose between minimal apis and controller based really depends on your situation and what you find best for your code base okay so that's my answer to the question I hope that answers it if not or if you have more questions go to suggestions dot I am Tim corey.com thanks for listening and as always I am Tim Corey [Music] thank you
Info
Channel: IAmTimCorey
Views: 27,099
Rating: undefined out of 5
Keywords: .net, C#, Visual Studio, code, programming, tutorial, training, how to, tim corey, C# course, C# training, C# tutorial, .net core, vs2022, .net 6
Id: 8D9gG5jmrI0
Channel Id: undefined
Length: 7min 40sec (460 seconds)
Published: Thu Aug 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.