End-to-end typesafe APIs made easy
@trpc/client
Communicate with a tRPC server on the client side.
Documentation
Full documentation for @trpc/client
can be found here
Installation
npm install @trpc/client@next
yarn add @trpc/client@next
pnpm add @trpc/client@next
Basic Example
import { createTRPCClient, createTRPCClientProxy } from '@trpc/client';
import type { AppRouter } from './server';
const client = createTRPCClient<AppRouter>({
url: 'http://localhost:2022',
});
const proxy = createTRPCClientProxy(client);
async function main() {
const helloResponse = await proxy.greeting.query({
name: 'world',
});
console.log('helloResponse', helloResponse);
}
main();