Is this a better way to build APIs?

Поделиться
HTML-код
  • Опубликовано: 18 янв 2023
  • A quick look at tRPC.
    💬 Topics:
    - Working with tRPC;
    - Alternative to REST and GraphQL;
    - Remote Procedure Call;
    - Authentication.

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

  • @erickmoya1401
    @erickmoya1401 Год назад +21

    Can't believe we went back to strong types, memory management and rpc. Software is amazing.

    • @awesome-coding
      @awesome-coding  Год назад +3

      It all goes in circles :))
      A couple of days I posted something related to this - ruclips.net/video/ntzuRtFZ8KM/видео.html

  • @armandsalle8447
    @armandsalle8447 Год назад +22

    tRPC made me fullstack as a TS frontend dev. I love tRPC and Zod

  • @amorfati8277
    @amorfati8277 Год назад +2

    Great stuff Mate🔥🔥. Always waiting for your uploads. They are great for checking out new technologies.

    • @awesome-coding
      @awesome-coding  Год назад

      Much appreciated! Thank you for your support!

  • @Matojeje
    @Matojeje Год назад +3

    This looks really cool! The client side code is very readable and easy to understand, more so than when using REST APIs, but I can barely grasp what's happening on the server side.

  • @biku1998
    @biku1998 Год назад +5

    Do you think it fits the situation in which there are multiple teams for frontend and backend and they are following a multi repo approach. I may be wrong but it looks more like a monolithic approach.

    • @awesome-coding
      @awesome-coding  Год назад +1

      Hey, @sourabhkumar9876 !
      Honestly, I don't have a lot of experience with mono repo tools, but I think tRPC would do good there since code is so easily shared.
      If you are thinking about multi repos - meaning some sort of micro services architecture, things could be a bit more tedious. I think it depends a lot on the architecture you are going with, but I expect you'd need to come up with some "tricks" to have your client code work with multiple trpc server instances.
      Definitely a topic worth looking into in more detail.

  • @tankimloong2738
    @tankimloong2738 Год назад +11

    It looks like it'll only work on monorepos where server and client are updated and deployed together. I am not sure if this will work as seamlessly across multiple repos. If I have 1 server and 5 clients all in different repo I'll need to update everything. The only real benefit here is the type definition being generated 'automatically' on server side, as compared to using openAPI spec or manually defining them. Still an improvement for sure

    • @tankimloong2738
      @tankimloong2738 Год назад

      @Tee Leo I suppose we're looking at two different aspects here. 1. Different communication technologies (RPC Vs graphql) and 2. Ease of development (how easy it is to share definition/generated SDK/code between projects).
      I'll skip 1 since I think we can probably agree they are rather different.
      As for 2, will using graphql libraries increase the ease of development in non-monorepo? As far as I know you'll still need to generate client stub/code from protobuf so it's not that different from openAPI or even trpc in this case.
      Or are you commenting on a different point altogether?

    • @tankimloong2738
      @tankimloong2738 Год назад

      ​@Tee Leo docs/faq#is-a-monorepo-mandatory. Can't seem to post link here so I removed trpc's domain. It seems that monorepo is not mandatory but not using it practically brings us back to step 1 with the disadvantages in the first place.
      You're still right that it's designed to work with monorepo, just that it's not a hard constraint so thanks for pointing that out!

  • @roya1jr
    @roya1jr Год назад +2

    You can also use asdf to switch between different language version including node

  • @N3m3s7s83
    @N3m3s7s83 Год назад +2

    Nice but... On the server side it looks like is Typescript only, which is not a limitation of rest/graphql/grpc, am I right?

    • @cokoala5137
      @cokoala5137 Год назад

      Yeah that’s the main caveat. Although there have been discussions about this concern, it’s still early days

  • @JokeryEU
    @JokeryEU Год назад

    a simpler way would say to not keep the client and server in the same repo, its to make the export of the types remote, like having an addon where it linked to the servers and it automatically shows the available routes you are allowed in client without needing to have the server in the same repo

  • @IainSimmons
    @IainSimmons Год назад

    You said tRPC has no dependencies, but it uses Zod (and I believe React/Tanstack Query)... Do you just mean you don't have to separately install things?

  • @ogreeni
    @ogreeni Год назад +2

    Do you really need tRPC in Next.js 13? Most of your data fetching will happen on the server side anyway.

    • @awesome-coding
      @awesome-coding  Год назад +2

      This is a legit question. The main benefit I'm seeing in most scenarios is trimming down the file system if you are really leveraging API routes.

    • @erickmoya1401
      @erickmoya1401 Год назад

      Next 13 is an unescapable curse, Trpc is supposed to be agnostic

  • @keent
    @keent Год назад +5

    only thing for me holding back on using tRPC is i couldn't integrate it well with Flutter/mobile apps.
    There's not much support for it for on mobile apps.

    • @awesome-coding
      @awesome-coding  Год назад +1

      I think it should work well with any hybrid mobile tech that relies on TS (things like react Native or Ionic for instance).
      The "issue" with flutter is Dart, and the lack of a tRPC client available for that environment. Sadly, I don't think we'll see a solution for this one any time soon.

    • @sheggi
      @sheggi Год назад

      maybe you'll be better suited with gRPC. gRPC exists longer than tRPC. the difference is the use of Protocol Buffers (like JSON, just binary). im sure, you're able to generate a client for Flutter.

    • @savire.ergheiz
      @savire.ergheiz Год назад

      Dart will always requires you to write proxy classes to adapt the json format for exchanges. You can go raw but yeah it against the benefit of the type safety being promoted here.

  • @raphaelqueiroz3105
    @raphaelqueiroz3105 Год назад +6

    pnpm is more efficient on all criterias than npm and yarn and supports node versioning aswell!
    Volta is also a nice alternative to nvm

    • @awesome-coding
      @awesome-coding  Год назад +2

      Thank you for pointing it out! This could actually be a good idea for a future video. 👍

  • @ryanfield8592
    @ryanfield8592 Год назад

    🔥

  • @th3f0r31gn3r
    @th3f0r31gn3r Год назад

    z is imported from which modules ?

    • @th3f0r31gn3r
      @th3f0r31gn3r Год назад

      ok ZOD got it now ;)

    • @awesome-coding
      @awesome-coding  Год назад

      import { z } from "zod"; :D
      Sorry for not making it more clear.

    • @th3f0r31gn3r
      @th3f0r31gn3r Год назад

      Thanks I already got it 😉

  • @sirajmussafirr147
    @sirajmussafirr147 Год назад +1

    How about gRPC? 🤔

    • @awesome-coding
      @awesome-coding  Год назад

      @sirajmussafirr147 Honestly I'm still on the fence regarding this RPC as an alternative to REST solution. tRPC makes sense because I can write isomorphic code and have my entire codebase written in TypeScript.
      Once we need to add a different language to the stack, I'm still more comfortable using established, standardised protocols such as REST or AMQP.

  • @AlexAegisOfficial
    @AlexAegisOfficial Год назад

    Quick tip: Use fnm instead of nvm. nvm on linux is really slow and breaks sometimes. nvm on windows is a completely different project and it's fine. But fnm is just an overall better solution, been using it for years now.

  • @greendsnow
    @greendsnow Год назад +6

    Svelte creates types for your server components
    AUTOMATICALLY

    • @awesome-coding
      @awesome-coding  Год назад +3

      Yep. As a downside though, Svelte Kit has the same issue as all other file system based router frameworks - a document tree that can easily get out of hand. For such scenarios tRPC brings way more value than the typesafety.

    • @greendsnow
      @greendsnow Год назад +1

      @@awesome-coding Oh. The old-school way is still open with SK. You can build a rest API on a single file, and eat your cake too

    • @alien19981
      @alien19981 Год назад +1

      What is the name of this feature?

  • @kamertonaudiophileplayer847
    @kamertonaudiophileplayer847 Год назад

    Consider also CORBA.

    • @awesome-coding
      @awesome-coding  Год назад +1

      Thanks for the suggestion! I'm not familiar with it. Any major selling points compared to REST + AMQP?

    • @kamertonaudiophileplayer847
      @kamertonaudiophileplayer847 Год назад

      ​@@awesome-coding Unfortunately, there are no selling points.

    • @awesome-coding
      @awesome-coding  Год назад +1

      @@kamertonaudiophileplayer847 Haha 😂 I figured!

  • @ZynthProductions
    @ZynthProductions Год назад +1

    The only thing i hate is this feel like getting back on the 2010s where frontend and backend become on the same project. I reeally hate the idea of monolithic app.

    • @awesome-coding
      @awesome-coding  Год назад +1

      We are definitely go in cycles. This is happening in all ecosystems though.. For a long time the monolith backend was the main option in the Java + Spring world Then, all of a sudden, micro services were the new trend, and everybody was writing micro services, even for the most basic apps... Then, a couple of years back I'm starting to see articles saying that monoliths are actually good, and they are the new trend 😒
      So I just stopped worrying about this stuf, and I'm focusing on gaining an understanding on various tools, so I can decide what's the best approach for specific projects. I'm also valuing more speed of development and maintainability more than scalability these days, but, at the end of the day it doesn't really matter since software has this habit of being rewritten form time to time -
      www.quora.com/Is-it-true-that-Google-re-writes-Gmail-or-other-products-every-3-years-to-get-rid-of-legacy-code

    • @ZynthProductions
      @ZynthProductions Год назад

      @@awesome-coding yes it is indeed also depends on the project scale. but still, even without micro service, separating backend and frontend app is still a good way. at least for me.

    • @awesome-coding
      @awesome-coding  Год назад

      @@ZynthProductions I can't argue with that :) you are right - it definitely is really compelling to have the backend and the frontend decoupled.

    • @ZynthProductions
      @ZynthProductions Год назад

      @@awesome-coding it is, having to imagine going back to have an apps that have bloated folder structure an size is 🤢

    • @erickmoya1401
      @erickmoya1401 Год назад

      But this is good. Microservices are not the same as multirepo. Sadly we got confused the last 10 years. But monorepos with multi-deployment are much more comfortable than multirepo - multideployment apps.

  • @YoannMaingon
    @YoannMaingon Год назад

    Are you the former codeworkr? :)

  • @dytra_io
    @dytra_io Год назад

    use trpc for new projects, not existing projects (period)

  • @vaylx2253
    @vaylx2253 Год назад

    Html first… RoR ftw.