You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RFC: Easier calling of tRPC queries with Postman etc #2480
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.stringifying 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:
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!
changed the title [-]feat: Easier usage with things like Postman etc[/-][+]feat: Prefix our query params in preparation of alternative ways of calling[/+]on Aug 18, 2022
changed the title [-]feat: Prefix our query params in preparation of alternative ways of calling[/-][+]RFC: Prefix our query params in preparation of alternative ways of calling[/+]on Aug 18, 2022
changed the title [-]RFC: Prefix our query params in preparation of alternative ways of calling[/-][+]RFC: Easier calling of tRPC queries with Postman etc[/+]on Aug 18, 2022
If someone is still keen to call their tRPC endpoints via Postman and unwilling to deal with the JSONRPC format then just encourage them to add trpc-openapi.
I agree with @jlalmes. This is not something that should be solved in core. trpc-openapi already handles this very well although you do have to specify the output schema. We could just adapt the solution there to only generate a REST API and only require output schemas / openapi meta when generating openapi documents.
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:
// move the request body into an `input` query param in the format trpc expects
// body.raw is already stringified json
const input = encodeURIComponent(pm.request.body.raw);
pm.request.addQueryParams(`input=${input}`);
// remove the request body
pm.request.update({
body: undefined
})
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?
Reacted by James Berry, Alex / KATT and Oscar Beaumont
Reacted by James Berry, Alex / KATT and Oscar Beaumont
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:
// move the request body into an `input` query param in the format trpc expects
// body.raw is already stringified json
const input = encodeURIComponent(pm.request.body.raw);
pm.request.addQueryParams(`input=${input}`);
// remove the request body
pm.request.update({
body: undefined
})
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?
Hey @felix-wooliesx, this looks awesome, do you wanna add something to the docs?
Activity
[-]feat: Easier usage with things like Postman etc[/-][+]feat: Prefix our query params in preparation of alternative ways of calling[/+][-]feat: Prefix our query params in preparation of alternative ways of calling[/-][+]RFC: Prefix our query params in preparation of alternative ways of calling[/+][-]RFC: Prefix our query params in preparation of alternative ways of calling[/-][+]RFC: Easier calling of tRPC queries with Postman etc[/+]jlalmes commentedon Aug 18, 2022
This is completely out of
tRPCscope. I am wholly against the@trpc/server&@trpc/clientsupporting and maintaining this functionality.The correct solution would be
Postman(or similar API testing platform) implementing a new integration/plugin fortRPC, just like they already have withgRPC(https://blog.postman.com/postman-now-supports-grpc/).Alternative solution for exploratory
tRPCAPI testing is @sachinraja'strpc-playground.If someone is still keen to call their
tRPCendpoints viaPostmanand unwilling to deal with theJSONRPCformat then just encourage them to addtrpc-openapi.sachinraja commentedon Aug 18, 2022
I agree with @jlalmes. This is not something that should be solved in core.
trpc-openapialready handles this very well although you do have to specify the output schema. We could just adapt the solution there to only generate a REST API and only require output schemas / openapi meta when generating openapi documents.KATT commentedon Aug 18, 2022
I'm happy with these answers. Thank you so much for the input, I will close this!
Also, method overloading will make this easier too.
What's your feels about the part of adding
transformeras a query param?jlalmes commentedon Aug 18, 2022
Meh, I'd leave it as-is. Ultimately I'd imagine
transformerwill be deprecated anyway after we implementContent-Types.felix-wooliesx commentedon Aug 20, 2022
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
inputquery 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?
KATT commentedon Aug 20, 2022
Hey @felix-wooliesx, this looks awesome, do you wanna add something to the docs?
felix-wooliesx commentedon Aug 23, 2022
Yeah sure I can look into that at some point soon 🙂
github-actions commentedon Oct 4, 2022
This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you.