← knowledge.oriz.in

Hono RPC type-sharing — `hc` client across sites

architecture architecturehonorpctype-safety

Hono RPC type-sharing

Shape

apps/api/src/index.ts ends with export type AppType = typeof app. The workspace package packages/api-client/ re-exports hc<AppType> configured against https://api.oriz.in. Every site and extension imports it:

import { client } from '@chirag127/api-client'
await client.routes.contact.$post({ json: { ... } })

Calls have full IntelliSense on payload + response shape.

Build flow

The Worker's AppType flows through the workspace boundary like any other type — no codegen, no .d.ts emit, no OpenAPI spec. Master matrix deploy publishes the Worker and @chirag127/api-client in lockstep so consumers never see type drift. A route signature change on the Worker breaks tsc in every consumer at the next CI run.

Cross-refs