End-to-end typesafe APIs made easy
Communicate with a tRPC server on the client side.
Full documentation for @trpc/client
can be found here
# npm
npm install @trpc/client@next
# Yarn
yarn add @trpc/client@next
# pnpm
pnpm add @trpc/client@next
# Bun
bun add @trpc/client@next
import { createTRPCClient, httpBatchLink } from '@trpc/client';
// Importing the router type from the server file
import type { AppRouter } from './server';
// Initializing the tRPC client
const trpc = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:3000/trpc',
}),
],
});
async function main() {
// Querying the greeting
const helloResponse = await trpc.greeting.query({
name: 'world',
});
console.log('helloResponse', helloResponse); // Hello world
}
main();