Call services from your application
Use contract-derived DTO types while keeping credentials and implementation code server-only.
Call the shared contract
Import contracts, not handlers or server composition. createClient uses native fetch in browser and server consumers.
import { createClient } from "@smoothie-framework/service/client";
import { ReadStatus } from "../../shared/contracts";
const client = createClient({ baseUrl: "http://localhost:3000" });
const status = await client.call(ReadStatus);
console.log(status.ready);Use a deployment-owned base URL. Configure cookies and origins deliberately; never bundle server secrets. Pass decoded path parameters—the client encodes each value once.
Choose the result style
call returns the success payload or throws. callResponse gives a discriminated result for status-aware UI.
const result = await client.callResponse(ReadStatus);
if (result.ok) {
console.log(result.data.ready);
} else {
// Narrow code and status before reading a domain-specific body.
console.error(result.code, result.status);
}Invalid input fails before transport. A cancelled or failed write may still have committed; reconcile its application identity before retrying.
For caching, see Query caching with TanStack Query.