RPC-Like Type-Safe API Calls with createAPIFileRoute in TanStack Start? #3731
yashwanth2804
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
I'm currently using TanStack Start's file‑based API routes with createAPIFileRoute to define my endpoints (e.g. /api/post/$id). My workflow is to call these endpoints via fetch (or with TanStack Query) on the client, which works well. However, I'd like to achieve a more RPC‑like experience where I can import these API route definitions directly and invoke them as if they were plain functions with full type inference—without having to manually wrap every fetch call.
Specifically, I'm looking for one of the following:
Built-in support: Is there a built‑in mechanism or recommended pattern in TanStack Start for calling your API routes in an RPC‑style way?
Custom wrapper ideas: If not, has anyone built a wrapper that abstracts away the HTTP call so I can simply call, say, rpcFetchPost(id) with full type safety?
Alternative recommendations: Or, is tRPC (or another library) the preferred solution for RPC‑like behavior while still using TanStack Start for routing?
Additionally, I noticed that in some examples (or even in certain docs) there’s a snippet like strin =g fetch ('/api/user') which appears to have typos. Has anyone encountered this or is there an updated reference for these examples?
Any guidance, examples, or recommendations would be greatly appreciated!
is there a type safe way of accessing the created api buy importing it , something similar to HONO RPC https://tanstack.com/start/latest/docs/framework/react/api-routes
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions