tRPC Plugin
This plugin adds support for using tRPC
Install with:
bash
bun add @elysiajs/trpc @trpc/server @elysiajs/websocket
bun add @elysiajs/trpc @trpc/server @elysiajs/websocket
Then use it:
typescript
import { Elysia, t as T } from 'elysia'
import { trpc, compile as c } from '@elysiajs/trpc'
import { z } from 'zod'
import { initTRPC } from '@trpc/server'
const t = initTRPC.create()
const p = t.prodcedure
const router = t.router({
greet: p
// or 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(8080)
import { Elysia, t as T } from 'elysia'
import { trpc, compile as c } from '@elysiajs/trpc'
import { z } from 'zod'
import { initTRPC } from '@trpc/server'
const t = initTRPC.create()
const p = t.prodcedure
const router = t.router({
greet: p
// or 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(8080)
trpc
Accept tRPC router and register to Elysia handler.
type:
trpc(router: Router, option?: {
endpoint?: string
}): this
trpc(router: Router, option?: {
endpoint?: string
}): this
Router
is the TRPC Router instance.
endpoint
The path to exposed TRPC endpoint.