TanStackT
TanStack6mo ago
3 replies
living-lavender

Making the api backend typesafe

Hello hello fellow builders.

I have a working webapp with some server functions for my frontend. Now I would like to make an http api as well for some of my users to consume.

I naively though I could just createServerFileRoute() and call my server-functions from here to also have a REST version of my stuff.

But since the API is pure http (not-rpc or anything sadly), I'm stumbling upon the famous DTO problem.
I have a Date to pass from front to back, which works fine in rpc but not classic http since it's serialized as a string.

I could make new zod schemas that instead of dates has string and then parsing them blabla.
Or... I could setup something like orpc on top of the nitro api backend.

What's the recommended way of achieving this ?
Also, does server-functions in the nitro backend are also just regular functions ?

Thanks.
Was this page helpful?