How to handle consistency for client-side only APIs?
Hi, we are using tRPC as a BFF (Backend for Frontend) which act as a proxy between ou UI and our dozen of backend services.
What's the recommended approach to handle direct client-side API calls when they cannot be implemented with tRPC due to legacy limitations?
Should we use React Query directly, or is there a way to extend tRPC's router in the client-side to maintain consistent API handling?
PS: For better understanding, we'd like to add client-side procedures because we need to calls APIs that can only be called in a browser
Solution:Jump to solution
```ts
export function buildTrpcClientFromRouter<AppRouter extends AnyRouter>(router: AppRouter) {
function mockLink<TRouter extends AnyRouter>(): TRPCLink<TRouter> {
return () => {...
8 Replies
are you basically trying to run a trpc server instance in the browser?
with a trpc client connecting directly to the same instance in the same page?
Oh nvm I misunderstood, disregard
cannot be implemented with tRPC due to legacy limitationsif it's because of the backend not supporting trpc, then react query is probably the best way to go
We cannot add procedures/mutations on the client-side by extending the router in any way?
"extending the router"? you can make a separate router probably, it's possible to make a router that calls a virtual server-side that's still running in your browser
That would do the trick yes, any example in mind?
here:
Solution
@Xavier
though I wrote this for trpc v11, you'd have to adjust it for v10
Thank you very much for your help, that looks perfect 🙏