mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
update readme
This commit is contained in:
28
README.md
28
README.md
@@ -75,12 +75,12 @@ console.log(farewell); // => 👈 goodbye
|
||||
|
||||
## Recipes
|
||||
|
||||
### Input validation
|
||||
### Input validation with [Zod](https://github.com/colinhacks/zod)
|
||||
|
||||
With [Zod](https://github.com/colinhacks/zod)
|
||||
tRPC works out-of-the-box with yup/superstruct/zod/myzod/custom validators. Learn more about input validation [here](https://trpc.io/docs/router#input-validation).
|
||||
|
||||
```ts
|
||||
// ~/trpc/index.ts
|
||||
// ~/server/trpc/index.ts
|
||||
import { z } from 'zod'
|
||||
|
||||
export const router = trpc
|
||||
@@ -99,28 +99,6 @@ export const router = trpc
|
||||
})
|
||||
```
|
||||
|
||||
With [Yup](https://github.com/jquense/yup)
|
||||
|
||||
```ts
|
||||
// ~/trpc/index.ts
|
||||
import { z } from 'zod'
|
||||
|
||||
export const router = trpc
|
||||
.router()
|
||||
.mutation('createUser', {
|
||||
// validate input with Zod
|
||||
input: yup.object({
|
||||
name: yup.string().required(),
|
||||
}),
|
||||
async resolve(req) {
|
||||
// use your ORM of choice
|
||||
return await UserModel.create({
|
||||
data: req.input,
|
||||
})
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
Learn more about tRPC.io [here](https://trpc.io/docs).
|
||||
|
||||
## License
|
||||
|
||||
Reference in New Issue
Block a user