Simultaneous use of RPC and OpenAPI handlers #651
-
First off, I am SO excited to see this project. I had been trying to work around a bunch of issues with tRPC and this solves every single one and more. I'm looking for an example of a server that uses both the RPCHandler and the OpenAPIHandler. I see in the creating a client docs that it looks like the rpc handler is mounted on Anyway awesome work. This is going to blow up. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There isn't a single-file example in the repo that shows both RPCHandler and OpenAPIHandler in one server, but the playgrounds for frameworks like Next.js and SvelteKit show the idiomatic pattern: mount RPCHandler at If you want OpenAPIHandler at To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
Thanks @dosu -- I also just found one here: https://github.com/unnoq/orpc/blob/main/playgrounds/contract-first/src/main.ts#L70 |
Beta Was this translation helpful? Give feedback.
There isn't a single-file example in the repo that shows both RPCHandler and OpenAPIHandler in one server, but the playgrounds for frameworks like Next.js and SvelteKit show the idiomatic pattern: mount RPCHandler at
/rpc
and OpenAPIHandler at/api
. Each handler is set up in its own route file, and both can coexist cleanly this way—no hacks needed. You can see this pattern in the Next.js playground for RPCHandler and OpenAPIHandler.If you want OpenAPIHandler at
/
instead of/api
, you can just change the prefix in the handler config and route file. The project doesn't recommend against this, but/api
is the default in the playgrounds. This setup is clean, maintainable, and lets you serve…