Hey API Integration
Easily convert a Hey API generated client into an oRPC client to take full advantage of the oRPC ecosystem.
Installation
npm install @orpc/hey-api@latest
yarn add @orpc/hey-api@latest
pnpm add @orpc/hey-api@latest
bun add @orpc/hey-api@latest
deno install npm:@orpc/hey-api@latest
Generating 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/client \
-c @hey-api/client-fetch
This command uses the OpenAPI spec at https://get.heyapi.dev/hey-api/backend
and outputs the generated client into the src/client
directory. And make sure you have @hey-api/client-fetch
installed.
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.