diff --git a/README.md b/README.md index e17027b..fa1019a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,55 @@ # tRPC-Nuxt -[![Build Size](https://img.shields.io/bundlephobia/minzip/trpc-nuxt?label=bundle%20size&style=flat&colorA=000000&colorB=000000)](https://bundlephobia.com/result?p=trpc-nuxt) [![Version](https://img.shields.io/npm/v/trpc-nuxt?style=flat&colorA=000000&colorB=000000)](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>() + // queries and mutations... + .query('hello', { + resolve: () => 'world', + }) + +// optional +export const createContext = () => { + // ... + return { + /** context data */ + } +} + +// optional +export const responseMeta = () => { + // ... + return { + // { headers: ... } + } +} +``` + +