Skip to content

tRPC Plugin ​

This plugin adds support for using tRPC

Install with:

bash
bun add @elysiajs/trpc @trpc/server @elysiajs/websocket

Then use it:

typescript
import { compile as c, trpc } from "@elysiajs/trpc";
import { initTRPC } from "@trpc/server";
import { Elysia, t as T } from "elysia";

const t = initTRPC.create();
const p = t.procedure;

const router = t.router({
  greet: p

    // ðŸ’Ą Using Zod
    //.input(z.string())
    // ðŸ’Ą Using Elysia's T
    .input(c(T.String()))
    .query(({ input }) => input),
});

export type Router = typeof router;

const app = new Elysia().use(trpc(router)).listen(3000);

trpc ​

Accept the tRPC router and register to Elysia's handler.

type:

trpc(router: Router, option?: {
    endpoint?: string
}): this

Router is the TRPC Router instance.

endpoint ​

The path to the exposed TRPC endpoint.