mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
Example: Added a basic example with a product call
This commit is contained in:
27
examples/basic-example/server/trpc/routers/index.ts
Normal file
27
examples/basic-example/server/trpc/routers/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { z } from 'zod'
|
||||
import { publicProcedure, router } from '../trpc'
|
||||
|
||||
export const appRouter = router({
|
||||
hello: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
text: z.string().nullish(),
|
||||
})
|
||||
)
|
||||
.query(({ input }) => {
|
||||
console.log(input)
|
||||
return {
|
||||
greeting: `hello ${input?.text ?? 'world'}`,
|
||||
}
|
||||
}),
|
||||
products: publicProcedure.query(async () => {
|
||||
return {
|
||||
title: 'TRPC Nuxt',
|
||||
price: 12.0,
|
||||
description: 'Check out the trpc-nuxt repo',
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
// export type definition of API
|
||||
export type AppRouter = typeof appRouter
|
||||
Reference in New Issue
Block a user