Next.js API Type Safety without tRPC?

I'm having issues with tRPC and am thinking of removing it from my project. Since I'm using App Router, it's less of a problem when calls are made on the server. However, I still need to make calls from client side. What are some good solutions for that?
7 Replies
Matvey
Matvey8mo ago
server actions
Mocha
MochaOP8mo ago
Yes, but I'm asking about the client side
Matvey
Matvey8mo ago
you can call server actions from the client
Mocha
MochaOP8mo ago
Yes, but I'm talking about things other than Server Actions. They're not ideal for everything. That's why people still use tRPC with App Router.
Sam!r
Sam!r8mo ago
You can try using Tanstack query. I have used it in a project and I wrap the layout with a Provider component. This does not interfere with my server actions and even lets me do client calls with all the tanstack query utilities.
Sturlen
Sturlen8mo ago
You might want to explain the problems you're having with tRPC and what your needs are, otherwise it's difficult to recommend anything
Mocha
MochaOP8mo ago
It was this issue that's currently fixed, but I just prefer not having a dependency if I don't really need it. If I could achieve almost the same results without tRPC, then it's better to remove this layer and keep the setup simple to develop and to debug TanStack libraries are awesome. Do you have some sample code or article that talks about this setup? Seems to me that the library works best either with tRPC or with external APIs. I haven't been able to find the "define a function and call it" experience anywhere else.
Want results from more Discord servers?
Add your server