Skip to main content

What is the RPC Client?

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.

Key Benefits

Type Safety

Full TypeScript support with type inference from server routes. Catch errors at compile time.

Zero Config

No code generation or build steps. Types are inferred directly from your Hono app.

Auto-complete

Get intelligent suggestions for routes, parameters, and response properties in your IDE.

Multi-runtime

Works anywhere JavaScript runs - browsers, Node.js, Deno, Bun, and edge runtimes.

Basic Setup

1. Define Your Server

First, create a Hono app with some routes:
Export the app type so it can be imported by your client code.

2. Create a Client

Import the app type and create a typed client:

How It Works

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.

Request Methods

The client generates methods for each HTTP verb, prefixed with $:
  • $get() - GET requests
  • $post() - POST requests
  • $put() - PUT requests
  • $patch() - PATCH requests
  • $delete() - DELETE requests
  • $options() - OPTIONS requests

Path Parameters

Path parameters use bracket notation in the client:

Configuration Options

You can pass configuration options when creating the client:
The init option has the highest priority and can overwrite settings that Hono sets for you, including body, method, and headers. Use with caution.

URL and Path Helpers

The client provides utility methods to construct URLs and paths:

What’s Next?

Type Safety

Learn about type inference and InferResponseType

Usage Examples

Explore request patterns and error handling