maxpowernz
maxpowernz12mo ago

Any Benefit using tRPC for only remote api calls?

Hi, does it make sense to use trpc if all I will be doing is calling a remote api? I have set it up succesfully with Azure storage tables, works well passing the table adapters as context. Just figuring out if theres any benefit calling an open Api v3 with trpc, or just stick with react query? Any advise much appreciated. Using Next v13^
1 Reply
PotatisMannen
PotatisMannen12mo ago
i would say its totally up to the pros and cons that you want. e.g. - using react query will make your setup a lot less involved but still give you what you need for caching + state management, so you're not losing out on good client side data management - the con of react query though is that once you need a custom stateful api you have to then default to making API routes which can be tedious boiler plate to set up - trpc has the benefit of being heavy lifting to set up (relatively speaking, its not exactly a lot of work), but once you are set up adding procedures is very easy compared to having to manage individual API routes and handling requests and responses with the native fetch api. - the con of trpc however is that consuming the api from outside your application loses out on the coupling you get from importing your trpc router, types and client instance into the respective parts of your application overall i'd say if you are exposing API routes already and you have that set up, then rather making a small client instance that serve data to those routes is straightforward and comes at no cost. If you dont have any routing set up though, might be good opportunity to use trpc P.S. take this with a pinch of salt 🤣 im only speaking from my own experience which is never a full picture