Nextjs http endpoint (no prisma)

DDevThoughts4/19/2023
I have simple pages/api/todoEndpint how do i call this endpoint with trcp? I don't want to use prisma?
FFast4/19/2023
Trpc has nothing to do with Prisma i would recommend reading this https://trpc.io/docs

And for the endpoint you would have to rewrite it to be defined in the trpc router as a procedure and not a regular nextjs endpoint
DDevThoughts4/19/2023
Thank you!
DDevThoughts4/19/2023
I started to understand:

import { z } from "zod"; import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; const url = "https://jsonplaceholder.typicode.com/todos"; export const exampleRouter = createTRPCRouter({ hello: publicProcedure .input(z.object({ text: z.string() })) .query(({ input }) => { return { greeting:Hello ${input.text}, }; }), getAllTodos: publicProcedure.query(async () => { const res = await fetch(url); const data = await res.json(); return data as Todo[]; }), });
DDevThoughts4/19/2023
Making a todos route but not getting type completion.
FFast4/19/2023
Does it just not show up on the client? and can you see the hello query?
DDevThoughts4/19/2023
yes, it did show up 🙂
Now i am unsure if this is right way to add types

getAllTodos: publicProcedure.query(() => { const data = fetch(url).then( (res): Promise<{ id: number; title: string; completed: boolean }[]> => res.json() ); return data; }),
FFast4/19/2023
Personally I think creating an interface and just casting the json result to it would be the cleanest (Would still have to check if the result of the fetch is correct eg status = 200) almost like how you did it in the first snippet