167. Should I Create A Minimal API Or Full API?

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

ความคิดเห็น • 60

  • @paulgehrman
    @paulgehrman ปีที่แล้ว +21

    Hi Tim, I love your comments about design patterns. I've been involved in software development for over 25 years and I've seen a lot of code bases. The single biggest issue by far in almost all bad code bases (with no close second) is the overuse of design patterns. Most of the time, code that is heavy with design patterns is nearly impossible to maintain, hard to read,, brittle etc. It is sad that design patterns are still pushed as much as they are, especially when there are often much simpler and robust alternatives. I appreciate you cautionary view, which is, for the most part, sorely missing in our community.

  • @rendellgood
    @rendellgood ปีที่แล้ว +21

    Wow I am literally in the middle of making this decision. Fantastic timing!

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +2

      Great!

    • @Aaron.Aguilar
      @Aaron.Aguilar 2 หลายเดือนก่อน

      What did you chose ?

    • @rendellgood
      @rendellgood 2 หลายเดือนก่อน

      @@Aaron.Aguilar I went with Controllers! Minimal APIs are nice for smaller projects, but for a larger project, controllers feel more maintaintable to me. Probably helps that they're familiar though.

  • @chrisnuk
    @chrisnuk ปีที่แล้ว +6

    True creativity requires the discipline to harness the chaos of imagination into the simplicity of brilliance

  • @hyxper2989
    @hyxper2989 11 หลายเดือนก่อน +1

    I think the real answer here is like what Tim said "it depends on your situation". I think my time in this space has taught me that most people try and denote solutions as "go to" or "old". I think a similar issue has spawned in the API space where developers who are trying to be cutting edge have heard that "Minimal APIs are the go to" and wont even consider looking at controller derived solutions. I think you just need to consider what is best for your solution. Need a micro service or simple API? great use a minimal solution and spin something up really quick. Need something with a little more control? Awesome then spin up a controller based solution and add some unit tests. I think if you can justify your decision, and it makes sense in terms of the business case, both solutions are equally as worthy. I just always try to not consider anything to be black or white, but what is going to work for me/my team.

    • @IAmTimCorey
      @IAmTimCorey  11 หลายเดือนก่อน +2

      I mostly agree with the "it depends", although I've fully moved over to minimal APIs over controller-based APIs now. I don't see the need for controllers and they add a layer of complexity that doesn't seem to be needed. You can do everything you need in a minimal API, including testing, separation of concerns, decorating, and more, but it is in a simpler format with less unnecessary ceremony.

  • @PyronTheMage
    @PyronTheMage ปีที่แล้ว +6

    Not sure if you already have a video but I'd like to see a "Should I use Razor Pages or MVC Controller/Views) video. I personally thought you can use both and to use Razor Pages for page-based scenarios but anything too complex then use or refactor to MVC controller/views.
    I see a lot of people saying "so glad I changed to Razor Pages and I've never looked back" and "MVC is dead" and I don't understand this.
    I've seen projects with a large collection of actions on 1 MVC controller. The view may have a lot of forms embedded on it with an action for each Post request that accepts all different Form Input Models, or the controller returns several different views and may, or may not, share the same view model (usually not a good idea to share view models but maybe there's a technical constraint). In this scenario, Razor Pages sounds like the wrong tool.

    • @ieaatclams
      @ieaatclams ปีที่แล้ว

      Mvc is a design pattern. You can do MVC on whatever stack you want. It's about segregation of items

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +6

      The situation you are describing sounds like an abuse of MVC. Controllers with lots of actions tend to be really messy and hard to maintain. MVC was developed in a time when the only option for C# on the web was WebForms. MVC provided a more structured, testable, modular approach to web development. It became really popular because of that. Now, we have lots of options for development. Razor Pages works well for single pages (index, error, about us, etc.) where there isn't a lot of interaction. MVC can do more complex code separation for larger server-side sites. We used to use it to provide data to client-side applications such as React, but that's not really the best solution anymore. Now we just use API for that. Server-side in general has fallen out of favor because people want rich, client-side interactivity. That's why we now have Blazor Server and Blazor WebAssembly. Two options to give us that client-side interaction while still using C#.

  • @acodersjourney
    @acodersjourney ปีที่แล้ว +1

    Your passion and dedication shine through.

  • @RicusNortje
    @RicusNortje ปีที่แล้ว +6

    I ran tests and also found that minimal API's are faster than MVC as you don't automatically get all the middleware (you have to explicitly opt into them). So I use that for bespoke gateway with YARP for rewriting but endpoint when I need extra logic but then back end services still use MVC as they are more complex and benifit form the structure

  • @CodeToLive-ms4jm
    @CodeToLive-ms4jm 8 หลายเดือนก่อน +1

    thank you a lot for the explaniation!! I used to use design pattern all the time even if it 's simple project, but after this video I guess I will reduce using it

    • @IAmTimCorey
      @IAmTimCorey  8 หลายเดือนก่อน

      I am glad it was helpful.

  • @AmirHosseinBagheri
    @AmirHosseinBagheri ปีที่แล้ว +2

    @IAmTimCorey
    I would argue against it in large organizations. I believe in templates more than simplicity. This gives the leverage of getting people onboard easily in an agile teams with turnovers.

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +4

      If you mean the built-in templates, they are almost useless in a large organization. The code of the organization will quickly grow beyond them to the point that the original template had little, if any, impact. In a large organization, it is better to establish coding standards and then apply them to your specific projects. That can include creating your own templates.

    • @avnishbadoni1393
      @avnishbadoni1393 ปีที่แล้ว +1

      I personally prefer breaking features out into modules (for monoliths). So for example, there's a Loyalty Points feature, just create a new folder... A new module. And have a single point of connection to the rest of the code.
      Then, there, a developer has freedom to choose any code structure they want to apply. Just for all the routes, controllers, service, models or any combination of these which are created within that module. Faster development with the devs coding style innately being used. And easy switching off and on that module.
      Also, close to zero merge conflicts.
      .
      And architecture could be made as simple or as complex as the requirement of the module.
      .
      This approach is something I experimented and created for a startup that started out as monolith, but was soon expected to grow to big scales.... And we needed the code seperation for easily breaking it up into a micro service architecture

  • @ionutb123
    @ionutb123 ปีที่แล้ว +1

    hi Tim, love your videos, I’m new to programming and I noticed that with Next.js, Blazor “United” and so on, you don’t need an API anymore, is that a trend? Thanks

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +1

      There is still a need for an API. It is just often hidden. For example, with the new Blazor (they've dropped the "united" word even though it was the best way to describe it), if you use Auto or WebAssembly, you get two projects. One is the front-end project and the other is the back-end project. The back-end acts as an API for the front-end.

    • @timrobertson8242
      @timrobertson8242 ปีที่แล้ว

      @@IAmTimCorey That's my current confusion. With WebAssembly deployment, how does the interaction with a Server Side resources happen if one doesn't also build an API layer over the Data Source and to avoid repeating myself, do I use the API for my Blazor Server components. My hope is that by digging into your latest Blazor course (with .NET8), I'll see how this unlocks. Thanks for the insight on end-points vs. MVC!

  • @torrvic1156
    @torrvic1156 ปีที่แล้ว

    Thanks a lot for the insight, Tim! This clarifies a lot.

  • @cissemy
    @cissemy ปีที่แล้ว +2

    Does minimal api gives better performance vs controller api?

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว

      Technically maybe, but it is more preference.

    • @blackpaw29
      @blackpaw29 ปีที่แล้ว +2

      @@IAmTimCorey I always get suspect on questions of performance when it comes down to fractional differences with function calls. Unless they are being invoked 1000's of times a second, it rarely matters, but its a honey trap for the ocd tendencies of the coder psyche 😁.
      99.99% of the time, performance is impacted by algorithms, i/o and app design.

  • @monirahmad133
    @monirahmad133 ปีที่แล้ว +1

    You are answer my internal myself question, really thanks 🎉

  • @dasfahrer8187
    @dasfahrer8187 ปีที่แล้ว +2

    Controllers really aren't necessary anymore as the minimal API can be built out to be as exactly complex as necessary. They're so good.

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +2

      They are really great.

  • @patrickizekor6463
    @patrickizekor6463 ปีที่แล้ว

    Hi Mr Corey, Many thanks for your great videos that supports the developer community. Please i was wondering what project template in Visual studio is used for the development of minimal api's.

  • @reynaldoruizflores
    @reynaldoruizflores ปีที่แล้ว

    How many types of API's exist, and which ones are the modern ones? And which can be handled by Microsoft Technology?

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +1

      Microsoft provides the full API project type (with controllers) for both .NET Framework and .NET. They also provide the Minimal API project type for .NET. Finally, an Azure Function can be a very small API (single endpoint). But that's just the project types from Microsoft. Practically every programming language provides a way to create an API. APIs power a lot of the web and mobile applications out there, plus some desktop applications. If you build an API in C#, the best choice for a new project would be either a full API or Minimal API in .NET 6+
      As for your question about which ones can be handled by "Microsoft Technology" (I'm assuming you mean a C# application), the answer is any of them. An API is designed to be processed by anyone. That means you can write an API in Java and call it from C#. The same is true in reverse.

  • @DannyHodge95
    @DannyHodge95 ปีที่แล้ว

    Maybe I'm old school, but I'm very hesitant to pick up minimal API's in most scenario's. I do find that the fully structured API's are much easier to read/debug once they hit a certain size, and lets be honest, how many times does a "Small API" turn into a behemoth in industry?
    Perhaps this is just my experience though, curious if anybody else has experienced anything similar...

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +1

      Interesting. I haven't found full APIs to be any easier to debug. I've found that it is just a different way to do the same thing.

  • @blackpaw29
    @blackpaw29 ปีที่แล้ว +2

    Basically... it depends lol :), not disagreeing.
    A lot of my formative experience predates MVC and I never really got into it. Most of my work is backend services for data processing, which suit minimal apis well. My impression of MVC, is that its best used with User GUI's with a solid focus on standard CRUD.

  • @dennisvandermeer8238
    @dennisvandermeer8238 ปีที่แล้ว +3

    Do note that Controller-based API have some overhead that Minimal API does not have. For example Minimal API is missing Content Negotiation. As most (if not all) APIs only communicate in JSON this does not have a big impact and otherwise you'll have to add it manually (haven't figured out how to do this. Filters?). So Minimal APIs are faster.

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +1

      That difference is negligible, I believe, though.

  • @rikudouensof
    @rikudouensof ปีที่แล้ว +2

    Thanks for the video. Most videos you keep saying it. Avoid the complexity if it is not necessary.

  • @keyser456
    @keyser456 หลายเดือนก่อน

    How have you not talked about convention vs. configuration? Rhetorical question

    • @IAmTimCorey
      @IAmTimCorey  หลายเดือนก่อน

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @Anton-Os
    @Anton-Os ปีที่แล้ว

    Thank you!

  • @lkarabeg
    @lkarabeg 10 หลายเดือนก่อน +1

    While this is good general advice, I feel like it doesn't address the question in the title. I expected more concrete advice, e.g. "If you need action filters, you should use controllers" (true at the time the video was made).

    • @IAmTimCorey
      @IAmTimCorey  10 หลายเดือนก่อน

      The problem is that concrete advice on which to choose is almost always wrong. You need to make the right call based upon your specific situation.

    • @lkarabeg
      @lkarabeg 10 หลายเดือนก่อน

      @@IAmTimCorey If only someone had advice on which things to take into account, though. /s

    • @IAmTimCorey
      @IAmTimCorey  10 หลายเดือนก่อน

      That list includes:
      * your team's skills
      * how well your team can train up in minimal APIs
      * your existing code
      * the versioning of the libraries you depend on
      * the features you need to rely on in C# (more preference than prescriptive)
      * greenfield or brownfield API
      * any existing conventions or practices that would weight a choice
      * your preferences
      And this is a simpler issue, since both can do similar things.

  • @manasi-v9i
    @manasi-v9i ปีที่แล้ว

    Sir ❤❤

  • @ArthurSchoppenweghauer
    @ArthurSchoppenweghauer 2 หลายเดือนก่อน

    For the typical web dev acustomed to piling shit on top of other shit this must sound like heresy.

  • @kandycan
    @kandycan ปีที่แล้ว

    I think u should never go from controller based structure to minimal API structure. Reason is, codebase will surely get more and more complex even if it's not complex right now. Controllers provide separation of concerns. Now sometimes you may go for minimal API approach especially when you are breaking down monolithic architecture into microservices.
    But then in case of microservices and API code that won't expand or have more APIs or endpoints for different entities, then go for it. Make minimal API and let it run for years.

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว +3

      How does a controller add more of a separation of concerns compared to an endpoint? I can put endpoints in their own class(es) easily enough. They aren't any more coupled than controllers are.

  • @SayWhaaaaaaaaaaaaaaaaaaaaaaat
    @SayWhaaaaaaaaaaaaaaaaaaaaaaat 6 หลายเดือนก่อน

    AUDIO ASYNC IS SOO HORIBLE IN THIS VIDEO

    • @IAmTimCorey
      @IAmTimCorey  6 หลายเดือนก่อน

      If you close your eyes, the problem goes away. 😉 Sorry we can’t fix it any other way.