tRPC + external API

Hello. This might sound dumb but currently we need to expand the usability of our backend for a specific project. We will need to create a Typescript backend and I was thinking of using Next + tRPC. Question is, I will also need to interact with said backend on some cases but through tRPC endpoints in my app. Does doing this makes sense? And in that case, how can I make a tRPC procedure depend on a regular http call? Like for example formating some data and send it awaiting response from that POST call to our backend.
7 Replies
Nestor
NestorOP3y ago
Also I'm open to other ideas if you know any other viable option. We need to create a custom user/roles layer + move some complexity (mostly with formatting huge json objects) to the server essentially.
Matvey
Matvey3y ago
I think you are looking for this https://github.com/jlalmes/trpc-openapi
Nestor
NestorOP3y ago
I'll take a look, I guess this helps to access it externally?
Matvey
Matvey3y ago
Yeah, you can map a tRPC procedure to an HTTP endpoint
Nestor
NestorOP3y ago
Cool, that fixes one of my issues ! But, how about the other one. Can I await a fetch from a different API from a tRPC procedure ?
Matvey
Matvey3y ago
You can use any node library to make a request from a tRPC procedure node 18+ has fetch api built-in
Nestor
NestorOP3y ago
Oh wonderful, yeah we're using node 18 so all good Great, I'll take a look at how can I implement it, good to know it's possible
Want results from more Discord servers?
Add your server