trpc with third party api

is it possible to use trpc with rest api like jsonplaceholder?
4 Replies
mrnicericee
mrnicericee2y ago
yes, look at the dev tools -> network tab to look at the request being made, and look at the Request URL they're all HTTP request, you could postman or curl too if you wanted to
Lgy
LgyOP2y ago
I meant can I fetch data from something like jsonplaceholder inside my trpc instead of getting data from db like prisma and then call the function to get safely typed response from jsonplaceholder
Vengeance
Vengeance2y ago
Yes you can call a third party api from tRPC, just use axios or something but that's not going to automatically make the response typesafe, you need to parse that response, tRPC makes the response of your entire procedure typesafe, it doesnt know the types coming in from someplace like jsonplaceholder unless you tell it
cje
cje2y ago
There are a few ways to make an external api typesafe - if it has OpenApi definitions, use that - run the response through a zod validator - do both of the above - lie (just do “const data = await fetch url as SomeType”), but this isn’t actual type safety and will make bad stuff happen if they change the API
Want results from more Discord servers?
Add your server