CRUD APIs are Poor Design

Поделиться
HTML-код
  • Опубликовано: 4 дек 2024

Комментарии • 45

  • @anikaitmakkar989
    @anikaitmakkar989 10 часов назад +40

    Can we have a detailed video, where you refactor a CRUD based API based on the suggested principles

    • @CodeOpinion
      @CodeOpinion  10 часов назад +12

      Great suggestion!

    • @majormartintibor
      @majormartintibor 6 часов назад +4

      @@CodeOpinion would love that, please do it!

    • @marcwinner567
      @marcwinner567 2 часа назад

      Yeah please do this. @CodeOpinion. It works really help a lot

  • @joelv4495
    @joelv4495 11 часов назад +18

    💯. From a business perspective, we don't "create a shipment", we "SHIP an order".

    • @dyto2287
      @dyto2287 8 часов назад +4

      ......after you create a record of the shipment in your database and create additional shipment status events while it's ongoing.
      Cmon, stop thinking this must be one object.

  • @allenbythesea
    @allenbythesea 11 часов назад +12

    I've been opposed to the CRUD/REST paradigm since its inception. These concepts push business logic up into the UI instead of in the api/business layer. Glad to see others coming around as well.

    • @CodeOpinion
      @CodeOpinion  10 часов назад +3

      Agree'd. I advocate for hypermedia a lot to guide UI/clients but there is so much pushback or dismissal of it, I think it's too far gone.

    • @ing50c
      @ing50c 5 часов назад +1

      At its worst, it’s downright dangerous.
      I’ve worked at places where the data model was exposed as-is in this CRUD fashion, with nothing in place to enforce sanity.
      So if you had an Order entity, some other developer could come along and just PATCH it with a different customer ID.
      Zero encapsulation with the power entirely in the hands of the caller. It was a nightmare to work with.

    • @allenbythesea
      @allenbythesea 3 часа назад

      @@ing50c yes! I've said the same thing many times and been shouted down. Basically with CRUD and REST you are exposing your inner structures. Its crazy to me that people are just realizing what was obvious from the start. I blame those who just follow the blogs and don't think for themselves. So many times their retort to my argument was 'well such and such does it'.

  • @transientwaveform1475
    @transientwaveform1475 11 часов назад +5

    Louder for the people in the back!!! Systems built this way are wildly irresponsibly engineered in the real world, and yet it's so pervasive now because nobody challenges it because they assume it's "best practice" due to the tutorials they followed!!

  • @lost-prototype
    @lost-prototype 11 часов назад +2

    There are so many usual suspects of problems in CRUD systems, and it causes people to become so fixated on superficial DRY, high coupling, loss of context... The end is basically change data capture and never ending tack-ons to recapture lost context.
    CQRS/business operations.... Those are the way to go. Simple transaction scripts. Lean flows, even if there's a bit of duplication.
    You can always maintain multiple rich domain models.
    The bonus once you follow all the advice? Simpler test cases, higher level of certainty in the system.

  • @Rick104547
    @Rick104547 8 часов назад +1

    Currently working on a microservices application that just crud for the most part. It's horrible, the UI around it has alot of logic in it because its basically a big leaky abstraction.
    So now my team is busy consolidating the microservices and designing the endpoints around behavior instead of crud based endpoints. The UI is getting simpler every iteration and as a bonus faster.
    It works for tests as well, we used to have tests for every single method but that was just dumb. Now we test behaviors and sure the tests are larger in scope but the actually test things that are of value and they give us alot of freedom to refactor.
    The only one that seems to have a problem with it is weirdly enough our solution architect. This slows down our efforts a bit but we still get it done.

  • @vuhoang5903
    @vuhoang5903 10 часов назад +2

    I've been learning and exposed to CRUD apps since day 1, and this opens a new horizon for me.

  • @buriedstpatrick2294
    @buriedstpatrick2294 3 часа назад

    I think CRUD is so prevalent because the first thing a lot of developers are taught to make is a TODO list app.

  • @TheCardSlayer
    @TheCardSlayer 8 часов назад +2

    What would an API example look like in these cases?

  • @cloudbaud7794
    @cloudbaud7794 6 часов назад +1

    Need an end to end example

  • @majormartintibor
    @majormartintibor 7 часов назад +2

    I agree with you Derek, but would love to see how you design APIs that are not "CRUD/REST" for supporting business processes.

    • @Coburah
      @Coburah 7 часов назад +3

      Can't speak for Derek, but what my company does is use CQRS. All commands are pretty much self explanatory in terms of what they do and they all are executed with POST. They all accept tailor made input parameters for that particular command. Examples:
      POST api/users/createUser
      POST api/orders/updateShippingAddress
      POST api/orders/cancel
      All queries are done via GET in typical REST fashion.
      Simple.

    • @CodeOpinion
      @CodeOpinion  6 часов назад +6

      I plan on creating another video detailing that as I think it's a good idea if I can find an example that's primarily CRUD and change it to illustrate.

    • @svorskemattias
      @svorskemattias 5 часов назад

      @@Coburah I'm even doing queries with POST.

    • @Coburah
      @Coburah 4 часа назад

      @@svorskemattias sure, why not? REST dogma gives nothing imo. If the command is properly named, it should be apparent what it does. We use commands (POST) for queries that are more like "computations".

    • @svorskemattias
      @svorskemattias 3 часа назад

      @@Coburah
      I use POST mostly to just reduce my mental overhead. I don't need caching. There's always a body for parameters, no need to use queryparams or URL-segments for that.
      I only use GET when it's the browser that natively uses the URI, like for an IMG-tag.

  • @larsh8560
    @larsh8560 10 часов назад +1

    Vendors: "Our standard system have this great API you can use."
    Me: "That pile of turd? That's basically an APi wrapping CRUD operations on your database"

  • @adambickford8720
    @adambickford8720 10 часов назад +3

    CRUD is so predominant because many times, that's all you genuinely need. In fact, it might even be the majority and you *should* use it if it makes sense. If you're just going to essentially validate the input of your endpoint and persist it... do that. Don't invent some abstraction (DDD, OOP, etc) 'just in case' or for the sole purpose of semantic decoupling.
    Sometimes a cigar is just a cigar.

    • @CodeOpinion
      @CodeOpinion  9 часов назад +2

      Fully agree, except on the "it might even be the majority", Not so sure about that. Let CRUD be CRUD where that's truly what it is. However in my experience, in large business systems, that's not at all what it is.

    • @adambickford8720
      @adambickford8720 8 часов назад +1

      @@CodeOpinion I think it depends on the systems. I've worked on a lot of systems that have pages to essentially CRUD entities/data that are used in the actual business workflows in the app. Between that and pages of tabular/reporting views, they often end up with more 'surface area' than the business flows themselves.

    • @Coburah
      @Coburah 5 часов назад

      @@adambickford8720 I agree with this sentiment: CRUD fits neatly when you have essentially "forms for entities". Just load the "form", update in UI, send back to backend to persist. I guess the problem is that people then reuse that "form data" for other purposes...

  • @minor12828
    @minor12828 3 часа назад

    Isn't it supposed to have another layer ? Another layer above the crud layer ?

  • @patolorde
    @patolorde 3 часа назад

    i have a hard time modeling this

  • @istovall2624
    @istovall2624 6 часов назад

    i like crud based systems and then distributed events based off those, but i think that defining the crud event in smaller terms is appropriate. for example, update_user is too broad, update_user_email_by_admin is much better, and also update_user_email_by_user is much better, both are updates, and follow a crud pattern but are very fine grained because different events need to transpire based off of each action, which is essentially no different than what you described (i think???)

  • @jntaca
    @jntaca Час назад

    CRUD APIs are suitable for master (clients, products ) and configuration tables. Any update is pusblshed into an event channel.
    Transactional APIs trigger worflows and processes that modify transactional tables.
    Personally, I don't like microservices because of data integrity issues, I prefer to break the system into isolated modules/services that can rely on DB transactions / commitis and rollbacks.

  • @aslkdjfzxcv9779
    @aslkdjfzxcv9779 3 часа назад +1

    i like crud.

  • @cathrerinezetadrones3169
    @cathrerinezetadrones3169 3 часа назад

    Absolutely can relate!

  • @essamal-mansouri2689
    @essamal-mansouri2689 11 часов назад +1

    Big fan of all your videos!

  • @ianmarteens
    @ianmarteens 10 часов назад

    Yesssir! Wholeheartedly agreed.

  • @Kubkochan
    @Kubkochan 18 часов назад +1

    one of the best videos

  • @kahnfatman
    @kahnfatman 9 часов назад

    It depends. And people are lazy to think and shied away from making crucial decisions. Cover-my-assssssets strategy implemented from top to bottom.

  • @FaridAdamgrino
    @FaridAdamgrino Час назад

    The real issue here is the architecture of the system and not CRUD. You should not directly expose database tables through APIs. Also from the example you gave with CURD, one would fall into that trap if they don't do proper domain modelling or do not do proper abstractions; leaving "all logic to CRUD.

  • @Nir4023
    @Nir4023 11 часов назад +1

    Great, need a video like this about authentication flows, refresh mechanism, OIDC and OAuth

    • @CodeOpinion
      @CodeOpinion  10 часов назад +2

      Elaborate a bit more on what you mean.

    • @Nir4023
      @Nir4023 9 часов назад

      @CodeOpinion like the way most resources tell you to use jwt as if it is the standard or silver bullet for all situations, without pointing out the trade-offs one should be making and the specifications for each platform and the bigger architecture of the system like how now you can have a client component, a server component, a server action and, remote backend and a 3rd party intégration all in one single small app.
      We need more content explaining how context is king in various topic that are victim to the crowds mentality and chasing the shiny things!