MadaShindeInai
MadaShindeInai15mo ago

T3 app tRPC external calls

Currently i'm just making Post request and formatting my payload to
{
"0": {
"json": {
....data <--- actual data.
}
}
}
{
"0": {
"json": {
....data <--- actual data.
}
}
}
format. It works. Saw that people use trpc-openapi for that. Is it really necessary? What are downsides of my approach?
6 Replies
Dani;
Dani;15mo ago
Are you sending the request from a non-TS client? If so I suggest using trpc-openapi, that way you can strictly define REST-compliant endpoints. You also get the benefit of an openapi.yml schema, which you can use to generate HTTP clients in various programming languages. Your approach can (unlikely) break if there's any changes of the internal schema used by tRPC. This will likely not happen, but who knows?
MadaShindeInai
MadaShindeInai15mo ago
I'm sending a request from Clerk webhook (user.create, and maybe user update later). Maybe there are some kind of more smooth solutions for that?
Dani;
Dani;15mo ago
Your approach is fine IMO, maybe someone else has better ideas on how to handle it.
Alex / KATT 🐱
Alex / KATT 🐱15mo ago
you can simplify it a bit by removing ?batch=1
Alex / KATT 🐱
Alex / KATT 🐱15mo ago
you can read the RPC spec here https://trpc.io/docs/rpc
HTTP RPC Specification | tRPC
Methods Type mapping
MadaShindeInai
MadaShindeInai15mo ago
yeah. It become a bit easier. Maybe you also can suggest an easy way to check from what domain request was sent? (To drop everything that was sent not from Clerk) Upd. found that if using Clerk's webhooks, in opts.req.headers getting 'svix-webhooks/ ..." as user-agent. Will use that is identifier. Thank you.