Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@trpc/client

Package Overview
Dependencies
Maintainers
0
Versions
1076
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trpc/client

The tRPC client library

  • 11.0.0-rc.660
  • next
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is @trpc/client?

@trpc/client is a TypeScript-first framework for building end-to-end typesafe APIs. It allows you to create and consume APIs with full type safety, ensuring that your client and server are always in sync.

What are @trpc/client's main functionalities?

Creating a TRPC Client

This code demonstrates how to create a TRPC client that connects to a TRPC server running at 'http://localhost:4000/trpc'.

const trpc = require('@trpc/client');
const { createTRPCClient } = trpc;

const client = createTRPCClient({
  url: 'http://localhost:4000/trpc',
});

Making a Query

This code demonstrates how to make a query to the TRPC server to fetch a user with a specific ID.

const result = await client.query('getUser', { id: 1 });
console.log(result);

Making a Mutation

This code demonstrates how to make a mutation to the TRPC server to create a new user.

const newUser = await client.mutation('createUser', { name: 'John Doe' });
console.log(newUser);

Subscribing to a Subscription

This code demonstrates how to subscribe to a subscription on the TRPC server to listen for updates to a specific user.

const subscription = client.subscription('onUserUpdate', { userId: 1 }, {
  onData: (data) => console.log('User updated:', data),
  onError: (err) => console.error('Subscription error:', err),
});

Other packages similar to @trpc/client

FAQs

Package last updated on 07 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc