TanStack Start Integration
TanStack Start is a full-stack React framework. It built on top of Nitro and Fetch API. For additional context, refer to the Fetch Server Integration guide.
Basic
ts
import { RPCHandler } from '@orpc/server/fetch'
import { createAPIFileRoute } from '@tanstack/start/api'
const handler = new RPCHandler(router)
async function handle({ request }: { request: Request }) {
const { response } = await handler.handle(request, {
prefix: '/api/rpc',
context: {} // Provide initial context if needed
})
return response ?? new Response('Not Found', { status: 404 })
}
export const APIRoute = createAPIFileRoute('/api/rpc/$')({
GET: handle,
POST: handle,
PUT: handle,
PATCH: handle,
DELETE: handle,
})
ts
import { createAPIFileRoute } from '@tanstack/start/api'
import { APIRoute as BaseAPIRoute } from './rpc.$'
export const APIRoute = createAPIFileRoute('/api/rpc')(BaseAPIRoute.methods)
INFO
The handler
can be any supported oRPC handler, such as RPCHandler, OpenAPIHandler, or another custom handler.