Package Exports
- @trpc/client
- @trpc/client/links/httpBatchLink
- @trpc/client/links/httpLink
- @trpc/client/links/loggerLink
- @trpc/client/links/splitLink
- @trpc/client/links/wsLink
Readme
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
npm install @trpc/client
# Yarn
yarn add @trpc/client
# pnpm
pnpm add @trpc/clientBasic Example
import { createTRPCClient, createTRPCClientProxy } from '@trpc/client';
// Importing the router type from the server file
import type { AppRouter } from './server';
// Initializing the tRPC client
const client = createTRPCClient<AppRouter>({
url: 'http://localhost:2022',
});
// Creating a proxy, this allows for cmd+click to the backend function.
const proxy = createTRPCClientProxy(client);
async function main() {
// Querying the greeting
const helloResponse = await proxy.greeting.query({
name: 'world',
});
console.log('helloResponse', helloResponse); // Hello world
}
main();