高速に進み、何も壊さない。\nエンドツーエンドの型安全なAPIを簡単に実現。
フルスタックアプリケーションの生産性向上のために、TypeScript推論のフルパワーを体験してください。
自動型安全
サーバーサイドを変更?TypeScriptがファイル保存前のクライアント側でエラーを警告します!
高速開発体験
tRPCにはビルド/コンパイル工程が不要。コード生成やランタイムの肥大化、ビルドステップが発生しません。
フレームワーク非依存
すべてのJavaScriptフレームワーク・ランタイムと互換性があり、既存プロジェクトへの導入が容易です。
オートコンプリート
tRPCの使用はAPIサーバーコード用SDKのようで、エンドポイントに対する確信を持てます。
軽量バンドル
依存関係ゼロでクライアントサイドのフットプリントが最小限。軽量に動作します。
充実の機能
React、Next.js、Express、Fastify、AWS Lambda、Solid、Svelteなどに対応したアダプターを提供しています。
tsconstt =initTRPC .create ();constrouter =t .router ;constpublicProcedure =t .procedure ;constappRouter =router ({greeting :publicProcedure .input (z .object ({name :z .string () })).query ((opts ) => {const {input } =opts ;return `Hello ${input .name }` asconst ;}),});export typeAppRouter = typeofappRouter ;
tsconstt =initTRPC .create ();constrouter =t .router ;constpublicProcedure =t .procedure ;constappRouter =router ({greeting :publicProcedure .input (z .object ({name :z .string () })).query ((opts ) => {const {input } =opts ;return `Hello ${input .name }` asconst ;}),});export typeAppRouter = typeofappRouter ;
1
プロシージャを定義する
tRPC API作成の第一歩はプロシージャの定義です。
プロシージャはバックエンド構築に使用する関数で、composable(合成可能)かつクエリ・ミューテーション・サブスクリプションのいずれかになります。ルーターは複数のプロシージャを含みます。
この例ではZodバリデーターを使用し、クライアントからの入力がプロシージャが期待する正確な形式か検証します。クエリからは単純なテキスト文字列を返します。
ファイル末尾ではルーターの型をエクスポートし、すぐにフロントエンドコードで利用できるようにします。
tsconst {listen } =createHTTPServer ({router :appRouter ,});// The API will now be listening on port 3000!listen (3000);
tsconst {listen } =createHTTPServer ({router :appRouter ,});// The API will now be listening on port 3000!listen (3000);
2
HTTPサーバーを作成する
次に、appRouterを使用してHTTPサーバーを作成します。これでtRPCサーバーが起動しました!
tRPCには多数のアダプターが用意されており、お使いの環境に合わせて選択できます。Next.js、Express、Fetch API(Astro、Remix、SvelteKit、Cloudflare Workersなど)、Fastify、AWS Lambda、あるいは標準のNode HTTPサーバーに対応しています。
tsconst trpc = createTRPCClient<AppRouter>({links: [ httpBatchLink({url: 'ht tp://localhost:3000',}),],});const res = awaittrpc.greeting.query({ name: 'John' });
tsconst trpc = createTRPCClient<AppRouter>({link s: [httpBatchLink({url: 'ht tp://localhost:3000',}),],});const res = awaittrpc.greeting.query({ name: 'John' });
3
クライアントを接続してクエリを開始しましょう!
サーバーが起動したので、クライアントを作成してデータのクエリを開始できます。
クライアント作成時にAppRouter型を渡すことで、バックエンドAPIと完全に一致するTypeScriptのオートコンプリートとIntellisenseが提供され、コード生成が不要になります。
「従来のAPI層の必要性を取り除くことで、人々がmove fasterできるようにtRPCを構築しました。同時に、迅速な反復開発でもアプリケーションが壊れないという確信を持てるようにしています」
ぜひお試しいただき、ご意見をお聞かせください!
Alex/KATT
tRPCのクリエイター

Theo - t3.gg
@theo
The amount that tRPC has improved the quality of our code, the speed of our delivery, and the happiness of our devs is hard to comprehend. I know I shill it a lot but seriously, please try @trpcio

R. Alex Anderson 🚀
@ralex1993
🤯 tRPC 10 enables VS Code's "Change All Occurrences" feature to work _across the client/server boundary_! In this video, I rename a procedure input using "Change All Occurrences", and that change propagates to anywhere the input is used across the entire app. 🤩 cc @trpcio

Kent C. Dodds 🌌
@kentcdodds
If I didn't already get end-to-end type safety from @remix_run, I would 100% be investigating @trpcio very seriously. If you're not on Remix, I suggest you give it a look 👀

Sock, the dev 🧦
@sockthedev
If you are all in on TypeScript you MUST use tRPC for your API. No ifs, no buts. tRPC destroys the boundary between frontend and backend. You get to focus on building features for your app. Best tool for time to market hyper mode. Marry me @alexdotjs 💍

Lee Byron
@leeb
Hearing @theo and @mxstbr #tRPC and @GraphQL and find they agree that both are awesome and there’s a time and a place for each 💖

Jökull Solberg
@jokull
tRPC is insane. I’m building a Stripe integration – I return Stripe API payloads from the server I get the response data typed for my React components without even saving the files, as if I’m using the Stripe library on the frontend not backend. /cc @alexdotjs

Christian Legge
@christian_legge
Spent all of yesterday learning and implementing @trpcio and wow, what a great investment. I can't believe how much time I spent (read: wasted) validating and parsing queries and responses!

Dominik 🇺🇦
@TkDodo
That being said, we _are_ starting a production project right now, and we're using @nextjs with @trpcio . It's so good I don't even know where to start 🔥. Probably with the e2e type-safety 😍 Haven't thought about client state much but the former probably applies.

Cory House
@housecor
@trpcio Love it. Simple, strong types. Feels like a more elegant choice than plain REST or GraphQL when using TS in a monorepo.

Anders Bech Mellson
@andersmellson
Spent today playing with @trpcio v10 and I'm officially in love 😍 ps. Don't tell my wife 🙊

Mike | grabbou.eth 🚀
@grabbou
@theo @trpcio Totally. I am literally smiling every time I write a procedure, because it reminds of how hard it used to be in the past. Built-in errors, typed middleware (that can alter context), input validation. It's just massive!

Osama Qarem
@osamaqarem
I’ve been playing with @trpcio and Solito together and this is without a doubt the fastest way to iterate on an api/website/mobile app there is today 🔥
すべてのスポンサー
tRPCの持続的な開発を支えてくれる素晴らしいsponsorsの皆様に心から感謝しています。

