RFC: Easier calling of tRPC queries with Postman etc
See original GitHub issueSummary
This is a two-part thing:
- Prefix “tRPC query params” with a
_
- Enable users to easier query the endpoints with Postman, etc.
Describe the solution you’d like to see
Part 1 - Prefix queries
Prefix queries
- We should likely prefix
batch
,input
, etc with a_
(or maybe_trpc_
) - We should also make the use of a transformer being stated in the query params, like
_transform=1
so we can know on the backend if something was called with - already on the roadmap
Part 2 - allow querying without JSON.stringify
ing query input
Given a postById
procedure with this input
:
z.object({
id: z.string(),
})
It would be nice to be able to call the endpoint in both these ways:
/api/trpc/postById?_input=%7B%22id%22%3A%221%22%7D
(encodeURIComponent(JSON.stringify({ id: "1" }))})
/api/trpc/postById?id=1
Caveats / drawbacks
- How to deal with
id
was az.number()
?- Enforce coercion with a
.transform
?
- Enforce coercion with a
- How do we deal with
input
not being az.object()
? - Maybe a rule could be added on the
t
’sRootConfig
to enforce it to be an object - Maybe this should be dynamically opt-in or out so one could only allow it in i.e. development
- How to deal with more complex inputs? I.e.
z.object({ arr: z.array(z.string()) })
Desribe alternate solutions
- Not doing it or encouraging people to use trpc-openapi
- #1939 helps here too by allowing users to call
query
endpoints with aPOST
Additional information
Alternative new solutions to tRPC (that have way fewer other features) use this as a selling point w/o recognizing that we have a good reason of doing it this way.
👨👧👦 Contributing
- 🙋♂️ Yes, I’d be down to file a PR implementing this feature!
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
useQuery() - tRPC
The hooks provided by @trpc/react-query are a thin wrapper around @tanstack/react-query. For in-depth information about options and usage patterns, ...
Read more >Connect-Web: TypeScript library for calling RPC servers from ...
Connect-Web: TypeScript library for calling RPC servers from web browsers (buf.build) ... implementations make it easier to interop with the gRPC ecosystem.
Read more >Implementing a tRPC API with a Solid-Start Application
In this tutorial we hope to show you how to create Solid-Start application using a tRPC API implemented inside the Solid-Start application.
Read more >Build a full-stack TypeScript app using tRPC and React
Build a simple, full-stack TypeScript app using tRPC that will be type-safe when it comes to the code and across the API boundary....
Read more >Syntax - Tasty Web Development Treats – Podcast – Podtail
Full Stack Developers Wes Bos and Scott Tolinski dive deep into web development topics, explaining how they work and talking about their own...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My solution to this problem was to use a Pre-req script in postman to convert a standard JSON body into the encoded and stringified
input
query string param using the following snippet:This allows me to easily edit the data that’s sent as part of a query as it’s simply just editing JSON in the Body page in postman.
Perhaps a docs page outlining something like the above is all that’s needed in this case?
Yeah sure I can look into that at some point soon 🙂