T
TanStack•3w ago
quickest-silver

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.
3 Replies
deep-jade
deep-jade•3w ago
i think orpc seems like a decent approach. there was a recent Jack Herrington vid on YT showing it done with tanstack start
deep-jade
deep-jade•3w ago
Jack Herrington
YouTube
tRPC vs oRPC: Typesafe API battle!
šŸ‘‰ ProNextJS Course: https://pronextjs.dev šŸ‘‰ Don't forget to subscribe to this channel for more updates: https://bit.ly/2E7drfJ šŸ‘‰ Discord server signup: https://discord.gg/ddMZFtTDa5 šŸ‘‰ VS Code theme and font? Night Wolf [black] and BitstromWera Nerd Font Mono šŸ‘‰ Terminal Theme and font? oh-my-posh with custom prompt and BitstromWera...
deep-jade
deep-jade•3w ago
Another one I found is @heyapi/openapi-ts https://heyapi.dev. I am using that with nitro

Did you find this page helpful?