An API contract created with defineApi().
Optionaloptions: ClientOptionsClient options passed to @cleverbrush/web's createClient().
A fully typed unified client proxy.
import { createClient } from '@cleverbrush/client/react';
import { api } from './contract';
const client = createClient(api, {
baseUrl: 'https://api.example.com',
getToken: () => localStorage.getItem('token'),
});
// Direct fetch
const todos = await client.todos.list();
// React Query hooks
function TodoList() {
const { data } = client.todos.list.useQuery();
const mutation = client.todos.create.useMutation({
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: client.todos.queryKey()
});
}
});
}
// Streaming
for await (const line of client.todos.export.stream()) { ... }
Creates a unified typed client from an API contract.
Each endpoint on the returned object is callable (direct HTTP fetch, identical to
@cleverbrush/web'screateClient) and also exposes TanStack Query hooks as properties:await client.todos.list()— returns a Promiseclient.todos.list.useQuery(args?, options?)— reactive fetchclient.todos.list.useSuspenseQuery(args?, options?)— Suspense fetchclient.todos.list.useInfiniteQuery(getArgs, options)— paginated fetchclient.todos.create.useMutation(options?)— mutationsclient.todos.list.queryKey(args?)— cache key for manual opsclient.todos.list.prefetch(queryClient, args?)— pre-populate cacheclient.todos.export.stream(args?)— NDJSON streamingEach group also exposes a
queryKey()method for group-level cache invalidation.When the
cacheTagsmiddleware is active,useMutationhooks automatically invalidate TanStack Query entries for the affected group.