Hey API Integration
Easily convert a Hey API generated client into an oRPC client to take full advantage of the oRPC ecosystem.
WARNING
Hey API is still in an unstable stage. As a result, this integration may introduce breaking changes in the future to keep up with its ongoing development.
Installation
npm install @orpc/hey-api@latestyarn add @orpc/hey-api@latestpnpm add @orpc/hey-api@latestbun add @orpc/hey-api@latestdeno add npm:@orpc/hey-api@latestGenerating an Hey API Client
To generate a Hey API client, run the following command:
npx @hey-api/openapi-ts \
-i https://get.heyapi.dev/hey-api/backend \
-o src/clientThis command uses the OpenAPI spec at https://get.heyapi.dev/hey-api/backend and outputs the generated client into the src/client directory.
INFO
For more information on Hey API, please refer to the official documentation.
Converting to an oRPC Client
Once the client is generated, convert it to an oRPC client using the toORPCClient function:
import { experimental_toORPCClient } from '@orpc/hey-api'
import * as sdk from 'src/client/sdk.gen'
export const client = experimental_toORPCClient(sdk)
const { body } = await client.listPlanets()This client now behaves like any standard oRPC server-side client or client-side client, allowing you to use it with any oRPC-compatible library.
Error Handling
Internally, oRPC passes the throwOnError option to the Hey API client. If the original Hey API client throws an error, oRPC will forward it as is without modification ensuring consistent error handling.
