Back to Trpc

`@trpc/client`

packages/client/README.md

11.16.01.4 KB
Original Source
<p align="center"> <a href="https://trpc.io/"></a> </p> <h3 align="center">tRPC</h3> <p align="center"> <strong>End-to-end typesafe APIs made easy</strong> </p> <p align="center"> </p>

@trpc/client

Communicate with a tRPC server on the client side.

Documentation

Full documentation for @trpc/client can be found here

Installation

bash
# npm
npm install @trpc/client

# Yarn
yarn add @trpc/client

# pnpm
pnpm add @trpc/client

# Bun
bun add @trpc/client

AI Agents

If you use an AI coding agent, install tRPC skills for better code generation:

bash
npx @tanstack/intent@latest install

Basic Example

ts
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();