What is tRPC, when and where should I use it?
I recently came across tRPC while learning TypeScript and Zod. How, Where and When should I use it?
7 Replies
tRPC | tRPC
End-to-end typesafe APIs made easy
ok, so what explains the "what", but what about the "where" and "when"?
when: always, where: everywhere 🤭
jokes aside, trpc is great if you want to share types between ur frontend and backend, I use it for every website I make and love every minute of it.
what is the benefit over sveltekit actions or nextjs server comps?
ive never used sveltkit but you can use SSR and TRPC in conjunction with one another, using prefetch
but what is the appeal over a traditional rest api?
If you're only going to have one app for example nextjs, then probably server actions will do you just fine.
tRPC is beneficial when you want a dedicated API that you have multiple consumers of like a react app and a react native app for example.
Basically trpc is just a rest API framework just benefit is that you don't need to generate types on the frontend to consume the API endpoints and it integrates with things like react query really easily
So case scenario for example:
You have a react web app, a mobile app and a desktop app lets say.
You want your server in typescript, then trpc would be a perfect fit because you don't need to go through the traditional openapi specs + generating types on these frontends