Avancez vite sans rien casser. Des APIs end-to-end typesafe, simplifiées.
Découvrez toute la puissance de l'inférence TypeScript pour booster la productivité de votre application full-stack.
Sécurité de typage automatique
Modification côté serveur ? TypeScript vous avertira des erreurs côté client avant même d'enregistrer le fichier !
DX rapide
tRPC ne nécessite aucune étape de build ou compilation : pas de génération de code, de surcharge à l'exécution ni d'étape de construction.
Indépendant des frameworks
Compatible avec tous les frameworks et environnements d'exécution JavaScript. Facile à intégrer à vos projets existants.
Autocomplétion
Utiliser tRPC équivaut à utiliser un SDK pour le code serveur de votre API, vous offrant une confiance totale dans vos endpoints.
Taille de bundle légère
tRPC n'a aucune dépendance et une empreinte client minime, ce qui le rend extrêmement léger.
Tout inclus
Nous fournissons des adaptateurs pour React, Next.js, Express, Fastify, AWS Lambda, Solid, Svelte et bien d'autres.
Utilisé par
tRPC est éprouvé et approuvé par les principales équipes techniques et de nombreuses entreprises du Fortune 500.
Simple à utiliser avec
une expérience développeur inégalée
Il est rapide et facile de démarrer avec tRPC pour construire une API type-safe.
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
Définir vos procedures
La première étape pour créer une API tRPC est de définir vos procedures.
Les procedures sont les fonctions utilisées pour construire votre backend. Elles sont composable et peuvent être des queries, mutations ou subscriptions. Les routers contiennent plusieurs procedures.
Dans cette procedure, nous utilisons un validateur Zod pour garantir que les données d'entrée correspondent exactement au format attendu. Nous renvoyons également une chaîne de texte simple depuis la query.
À la fin du fichier, nous exportons le type du router pour l'utiliser côté frontend quelques instants plus tard.
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
Créer votre serveur HTTP
Ensuite, nous créons notre serveur HTTP en utilisant notre appRouter. Nous avons maintenant un serveur tRPC opérationnel !
tRPC propose de nombreux adaptateurs pour s'intégrer à votre environnement : Next.js, Express, l'API Fetch (Astro, Remix, SvelteKit, Cloudflare Workers, etc.), Fastify, AWS Lambda, ou un serveur HTTP Node standard.
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
Connectez votre client et commencez à interroger !
Maintenant que le serveur est opérationnel, nous pouvons créer un client et commencer à interroger les données.
Nous spécifions le type AppRouter lors de la création du client pour bénéficier de l'autocomplétion TypeScript et d'Intellisense correspondant à l'API backend, sans aucune génération de code !
"J'ai créé tRPC pour permettre aux développeurs de move faster en supprimant le besoin d'une couche API traditionnelle, tout en conservant la certitude que nos applications resteront stables lors d'itérations rapides."
Essayez-le et dites-nous ce que vous en pensez !
Alex/KATT
Créateur de 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 🔥
Tous les sponsors
Nous adorons nos formidables sponsors qui aident à assurer la pérennité de tRPC.

