https://github.com/elysiajs/elysia-trpc
A plugin for Elysia that add support for using tRPC
https://github.com/elysiajs/elysia-trpc
Last synced: about 2 months ago
JSON representation
A plugin for Elysia that add support for using tRPC
- Host: GitHub
- URL: https://github.com/elysiajs/elysia-trpc
- Owner: elysiajs
- License: mit
- Created: 2022-12-06T17:36:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-16T11:57:26.000Z (over 1 year ago)
- Last Synced: 2025-01-07T12:10:04.107Z (10 months ago)
- Language: TypeScript
- Size: 181 KB
- Stars: 24
- Watchers: 1
- Forks: 18
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-elysia - trpc - Plugin that add support for using tRPC. (Plugins)
README
# @elysiajs/trpc
A plugin for [elysia](https://github.com/elysiajs/elysia) that adds support for using tRPC.
## Installation
```bash
bun add @elysiajs/trpc
```
## Example
```typescript
import { Elysia, t } from 'elysia'
import { trpc, compile as c } from '@elysiajs/trpc'
import { initTRPC } from '@trpc/server'
const r = initTRPC.create()
const router = r.router({
greet: r.procedure.input(c(t.String())).query(({ input }) => input)
})
export type Router = typeof router
const app = new Elysia()
.use(trpc(router))
.listen(8080)
```
## API
This plugin extends the new method `trpc` to `Elysia` class.
### trpc
Register tRPC router.
```typescript
type tRPC = (router: Router, options?: TRPCOptions) => this
export interface TRPCOptions
extends Omit<
FetchHandlerRequestOptions,
'req' | 'router' | 'endpoint'
> {
/**
* tRPC endpoint
*
* @default '/trpc'
*/
endpoint?: string
}
```
## Note
WebSocket API is in an experimental state and unstable.
Is meant for experimental for better stabilization.