Skip to main content

Making Requests

The Hono RPC client provides a fluent API for making HTTP requests with full type safety.

GET Requests

Simple GET requests with no parameters:

GET with Query Parameters

Pass query parameters using the query property:
Array query parameters are automatically serialized as multiple parameters with the same key (e.g., tag=framework&tag=typescript).

POST Requests with JSON

Send JSON data using the json property:

POST with Form Data

Send form data using the form property:

Multiple Form Values

Form fields can have multiple values:

Path Parameters

Access routes with path parameters using bracket notation:

Multiple Path Parameters

Headers and Cookies

Request Headers

Add custom headers to individual requests:

Global Headers

Set headers for all requests when creating the client:

Dynamic Headers

Use a function to compute headers dynamically:

Async Headers

Headers can be computed asynchronously:

Cookies

Send cookies with your requests:

Handling Responses

Response Object

The client returns a standard Response object with typed methods:

JSON Responses

Text Responses

Blob and Binary Data

Error Handling

Status Code Checking

Handle different status codes with type narrowing:

Using res.ok

Check if the response is successful (status 200-299):
When using res.ok, TypeScript narrows the type to only success status codes.

Parsing Response Errors

Use the parseResponse utility for automatic error handling:

Middleware Error Responses

Handle errors returned from middleware:

Advanced Features

Custom Fetch Implementation

Provide your own fetch implementation:

Using with app.request

Test your API without making network calls:
This is perfect for testing - no need to start a server!

Custom RequestInit

Pass custom RequestInit options:
You can also override per request:
The init option takes the highest priority and can overwrite Hono’s settings for body, method, and headers.

Custom Query Serialization

Customize how query parameters are serialized:

WebSocket Support

Connect to WebSocket endpoints:

URL Utilities

Get Full URL

Generate the full URL for a route:

Get Path Only

Generate just the path (without domain):
These utilities are useful for generating links in your UI or for debugging.

Best Practices

Export a configured client to use throughout your app:
Create a wrapper for consistent error handling:
Don’t hardcode API URLs:
Use status code checks to narrow response types:

What’s Next?

Validators

Add runtime validation to your API

Middleware

Learn about Hono’s middleware system