@trpc/server

The tRPC server library

@trpc/server downloads @trpc/server version @trpc/server license

@trpc/server유사 패키지:
npm 다운로드 트렌드
3 년
🌟 @trpc/server의 README.md에 실시간 사용 차트를 표시하려면 아래 코드를 복사하세요.
## Usage Trend
[![Usage Trend of @trpc/server](https://npm-compare.com/img/npm-trend/THREE_YEARS/@trpc/server.png)](https://npm-compare.com/@trpc/server#timeRange=THREE_YEARS)
Cumulative GitHub Star Trend
🌟 @trpc/server의 README.md에 GitHub Stars 트렌드 차트를 표시하려면 아래 코드를 복사하세요.
## GitHub Stars Trend
[![GitHub Stars Trend of @trpc/server](https://npm-compare.com/img/github-trend/@trpc/server.png)](https://npm-compare.com/@trpc/server)
통계 세부사항
패키지
다운로드
Stars
크기
Issues
발행일
라이선스
@trpc/server1,524,06138,8031.93 MB1867日前MIT
@trpc/server의 README

tRPC

tRPC

End-to-end typesafe APIs made easy

Demo

@trpc/server

Create tRPC routers and connect them to a server.

Documentation

Full documentation for @trpc/server can be found here

Installation

# npm
npm install @trpc/server

# Yarn
yarn add @trpc/server

# pnpm
pnpm add @trpc/server

# Bun
bun add @trpc/server

We also recommend installing zod to validate procedure inputs.

Basic Example

import { initTRPC } from '@trpc/server';
import {
  CreateHTTPContextOptions,
  createHTTPServer,
} from '@trpc/server/adapters/standalone';
import { z } from 'zod';

// Initialize a context for the server
function createContext(opts: CreateHTTPContextOptions) {
  return {};
}

// Get the context type
type Context = Awaited<ReturnType<typeof createContext>>;

// Initialize tRPC
const t = initTRPC.context<Context>().create();

// Create main router
const appRouter = t.router({
  // Greeting procedure
  greeting: t.procedure
    .input(
      z.object({
        name: z.string(),
      }),
    )
    .query(({ input }) => `Hello, ${input.name}!`),
});

// Export the app router type to be imported on the client side
export type AppRouter = typeof appRouter;

// Create HTTP server
const { listen } = createHTTPServer({
  router: appRouter,
  createContext,
});

// Listen on port 2022
listen(2022);