Aller au contenu principal

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.

Supported by

Many thanks to all of our amazing sponsors!

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.

  • Cal.com
  • Documenso
  • Google
  • Langfuse
  • Mistral
  • Netflix
  • PayPal
  • Ping.gg
  • Pleo

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.

ts
const t = initTRPC.create();
 
const router = t.router;
const publicProcedure = t.procedure;
 
const appRouter = router({
greeting: publicProcedure
.input(z.object({ name: z.string() }))
.query((opts) => {
const { input } = opts;
const input: { name: string; }
 
return `Hello ${input.name}` as const;
}),
});
 
export type AppRouter = typeof appRouter;
ts
const t = initTRPC.create();
 
const router = t.router;
const publicProcedure = t.procedure;
 
const appRouter = router({
greeting: publicProcedure
.input(z.object({ name: z.string() }))
.query((opts) => {
const { input } = opts;
const input: { name: string; }
 
return `Hello ${input.name}` as const;
}),
});
 
export type AppRouter = typeof appRouter;

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.

ts
const { listen } = createHTTPServer({
router: appRouter,
});
 
// The API will now be listening on port 3000!
listen(3000);
ts
const { 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.

ts
const trpc = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:3000',
}),
],
});
 
const res = await trpc.greeting.query({ name: 'John' });
ts
const trpc = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:3000',
}),
],
});
 
const res = await trpc.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 !

Vous n'avez peut-être pas besoin d'une API traditionnelle

"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

Alex/KATT

Créateur de tRPC

Ne vous fiez pas qu'à notre parole !

De nombreux développeurs adorent tRPC et ce qu'il leur apporte.

theo

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
ralex1993

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
kentcdodds

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 👀
sockthedev

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 💍
leeb

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 💖
jokull

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

@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!
TkDodo

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.
housecor

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.
andersmellson

Anders Bech Mellson

@andersmellson

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

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!
osamaqarem

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.