Saltar al contenido principal

Muévete rápido y no rompas nada.\nAPIs con seguridad de tipos de extremo a extremo hechas fácil.

Experimenta todo el poder de la inferencia de TypeScript para impulsar la productividad en tu aplicación full-stack.

Supported by

Many thanks to all of our amazing sponsors!

Seguridad de tipos automática

¿Hiciste un cambio en el servidor? TypeScript te alertará de errores en tu cliente ¡antes de guardar el archivo!

Experiencia de desarrollo ágil

tRPC no requiere pasos de compilación, evitando generación de código, inflamiento en runtime o procesos de build.

Independiente del framework

Compatible con todos los frameworks y entornos JavaScript. Fácil de integrar en proyectos existentes.

Autocompletado

Usar tRPC es como usar un SDK para tu API en el servidor, brindando confianza en tus endpoints.

Tamaño de paquete ligero

tRPC tiene cero dependencias y una huella mínima en el cliente, manteniéndolo liviano.

Baterías incluidas

Ofrecemos adaptadores para React, Next.js, Express, Fastify, AWS Lambda, Solid, Svelte y más.

Utilizado por

tRPC es probado y confiado por equipos tecnológicos líderes y muchas empresas Fortune 500.

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

Sencillo de usar con
una experiencia de desarrollo inigualable

Es rápido y sencillo comenzar con tRPC para construir una API con seguridad de tipos.

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

Define tus procedures

El primer paso para crear una API tRPC es definir tus procedures.

Los procedures son las funciones que usaremos para construir tu backend. Son composable y pueden ser queries, mutations o subscriptions. Los Routers contienen múltiples procedures.

En este procedure, usamos un validador Zod para asegurar que la entrada del cliente tenga exactamente la forma que espera nuestro procedure. También devolveremos una cadena de texto simple desde la query.

Al final del archivo, exportamos el tipo del router para poder usarlo en nuestro código frontend en unos momentos.

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

Crea tu servidor HTTP

A continuación, creamos nuestro servidor HTTP usando appRouter. ¡Ahora tenemos un servidor tRPC funcionando!

tRPC cuenta con múltiples adaptadores para integrarse en tu entorno actual: Next.js, Express, Fetch API (Astro, Remix, SvelteKit, Cloudflare Workers, etc.), Fastify, AWS Lambda o un servidor HTTP Node estándar.

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

¡Conecta tu cliente y comienza a consultar!

Con el servidor en funcionamiento, podemos crear un cliente y comenzar a consultar datos.

Al crear el cliente, pasamos el tipo AppRouter para obtener autocompletado de TypeScript e Intellisense que coinciden exactamente con la API del backend, ¡sin necesidad de generación de código!

Quizás no necesites una API tradicional

"Creé tRPC para permitir a los desarrolladores move faster eliminando la necesidad de una capa API tradicional, manteniendo la confianza en que nuestras aplicaciones no fallarán durante iteraciones rápidas."

¡Pruébalo y cuéntanos tu opinión!

Alex/KATT

Alex/KATT

Creador de tRPC

¡No te quedes solo con nuestra palabra!

Muchos desarrolladores adoran tRPC y lo que les aporta.

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 🔥

Todos los Patrocinadores

Valoramos enormemente a nuestros increíbles sponsors que aseguran que tRPC permanezca activo.