mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-24 00:40:31 +01:00
update readme
This commit is contained in:
51
README.md
51
README.md
@@ -1,6 +1,55 @@
|
||||
# tRPC-Nuxt
|
||||
|
||||
[](https://bundlephobia.com/result?p=trpc-nuxt)
|
||||
[](https://www.npmjs.com/package/trpc-nuxt)
|
||||
|
||||
End-to-end typesafe APIs with [tRPC.io](https://trpc.io/) in Nuxt applications.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm i trpc-nuxt -D
|
||||
```
|
||||
|
||||
```ts
|
||||
// nuxt.config.ts
|
||||
import { defineNuxtConfig } from 'nuxt'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
modules: ['trpc-nuxt'],
|
||||
})
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Create your tRPC [routes](https://trpc.io/docs/router) and [context](https://trpc.io/docs/context) under `server/fn/index.ts`:
|
||||
|
||||
```ts
|
||||
// ~/server/fn/index.ts
|
||||
import type { inferAsyncReturnType } from '@trpc/server'
|
||||
import * as trpc from '@trpc/server'
|
||||
|
||||
export const router = trpc
|
||||
.router<inferAsyncReturnType<typeof createContext>>()
|
||||
// queries and mutations...
|
||||
.query('hello', {
|
||||
resolve: () => 'world',
|
||||
})
|
||||
|
||||
// optional
|
||||
export const createContext = () => {
|
||||
// ...
|
||||
return {
|
||||
/** context data */
|
||||
}
|
||||
}
|
||||
|
||||
// optional
|
||||
export const responseMeta = () => {
|
||||
// ...
|
||||
return {
|
||||
// { headers: ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user