Stack Builder
Stack Builder
25 files412 lines
apps › web › src › client › lib › api.tsAPI client
import { createORPCClient } from "@orpc/client";import { RPCLink } from "@orpc/client/fetch";import type { RouterClient } from "@orpc/server";import { createTanstackQueryUtils } from "@orpc/tanstack-query";import type { Router } from "@my-app/api/router";
const link = new RPCLink({ url: () => new URL("/api/rpc", window.location.origin).href, fetch: (input, init) => fetch(input, { ...init, credentials: "include" }),});const client: RouterClient<Router> = createORPCClient(link);
/** The one way the UI calls the API: api.<feature>.<call>.queryOptions() or .mutationOptions(). */export const api = createTanstackQueryUtils(client);Placed by API: oRPC · Back end: Hono · Apps: One appTypeScript14 lines647 B