Okay, so if I jump into the description of this API and I change something, immediately in the front-end, so if I change something in the backend, immediately in the front-end TypeScript say to me, okay, you are doing something wrong. And this is a great thing because we didn't basically generate any kind of type, but out of the box, TypeScript give us this possibility.
Okay, so we can, okay, we can do like this. Again, I run a server to show you the application. This is a basic application, so we can save authors and delete authors as well. If we inspect our network tab, we can see that every time I click save, we are doing an HTTP request. And if we look into the source code, if I put a breakpoint inside of the library, here we are inside of trpc slash client slash dist, so the file inside of the library, you can see that if I click save here, I have a breakpoint in my Visual Studio code, and basically we are calling slash API slash trpc author list to grab all the authors. We are doing a query, so query is a get, mutation is a post, then we have a signal to abort the fetching. And if I run again my code, you can see that we are adding an author basically.
Great, so I want to deep dive also into the backend part so if we put inside of the other file, here in the author, I can put a breakpoint here in the add part so I can save. And then here in the left part I can inspect the stack of the calls and we can jump into the server part. So trpc server, I encourage you to debug the library, not only this one, but library in general, to understand how it works under the hood, it's really fun. And as you can see, if we save something, again, I think we are in the breakpoints, maybe we can go on a little bit. You can see that here we have our information and instead of this OPTS we have these procedures. We have the Add, Delete, List, great. And we have also our files. So our definition. So this is our code. Great. Let's jump again to the slides.
So there are a lot of pros about TRPC, no code generation. We have TypeSafe by default because we use TypeScript and we can collaborate better between the frontend and the backend. There are a few cons. We need to have a TypeScript stack, frontend and backend in TypeScript. Monorepo fits really well with this library, but you can have also multi-repo. If we want to have versioning or selecting field feature, we need to implement our own code. And if we want to expose our API in the public, we need to use an external library, trpc-openAPI. Well, let's summarize a little bit with this website. You can start with a fresh application with Prisma, Next, Tailwind, and Next.js, of course. Who is using trpc in this issue? You can find a lot of company that are using trpc, and now it's your turn. Let's try it out. With this website, you can find a lot of collection and resources about trpc. Thanks for watching. You can find me on Twitter. My handle is giorgio underscore boa. Have a nice conference.
Comments