Raw HTTP Requests to TRPC
Hey,
I have an api route that I need to create in my nextjs app that will be called from a non-javascript client.
How would u make a http POST request to a TRPC route?
7 Replies
According to my knowledge (someone else please correct me), you dont. Trpc has only got one end point which all trpc querys/mutations go through.
You can still define regular nextJS api routes for external apis to use
ah fair enough, may as well just use regular api routes then
i could in theory pass the correct json structure ut ehh
I am not familiar enough on that point sadly. I think so, you can always look at a trpc request in the network tab in chrome to see what it sends. It goes through TanStack Query though, so I dont know how that deals with regular http requests.
And there is one additional caveat which might trip you up. The t3 stack adds superjson on top of tRPC, so everything you can normally pass in a t3 app cant actually be passed through regular json. Like arbitrary objects/classes
ah rip hmm
coz right now im trying to use create-t3-turbo,
and the other issue is using trpc with the expo app, as i am now using auth0 for auth lol. its a bit of a pain coz the session dont exist between the 2 apps
Ah, well I have no experience with t3-turbo sadly. Ive only done native android development. I'd probably just use api routes for this, but if some tRPC magician knows more than me I'd happily learn a lesson for the future
haha fair
the auth0 nextjs docs are so bad
literally cannot find what im suppose to use to auth in an api route using a bearer token
you could:
- look in the network tab what the requests to trpc look like and copy that
- use trpc-openapi
- just use a normal next.js api route for this one thing