The Hono RPC (Remote Procedure Call) client provides a type-safe way to make HTTP requests to your Hono server. Using the hc() function, you get full TypeScript type inference for routes, request parameters, and response data - all derived directly from your server definitions.
import { hc } from 'hono/client'const client = hc<typeof app>('http://localhost:8787')
import { hc } from 'hono/client'import type { AppType } from './server'const client = hc<AppType>('http://localhost:8787')// Make requests with full type safetyconst res = await client.hello.$get()const data = await res.json()console.log(data.message) // TypeScript knows this is a string
The RPC client uses TypeScript’s powerful type inference to extract route information from your Hono app. When you call hc<typeof app>(), TypeScript analyzes your app’s route definitions and generates the appropriate client methods.
// Server sideconst app = new Hono() .get('/api/users/:id', (c) => { return c.json({ id: 123, name: 'John' }) })// Client side - TypeScript infers everythingconst client = hc<typeof app>('http://localhost')const res = await client.api.users[':id'].$get({ param: { id: '123' } // TypeScript knows this param is required})const user = await res.json()// TypeScript knows user has { id: number, name: string }