Skip to content

Feature Request: Built-in typed RPC client for edge environments (Cloudflare Workers & Deno Deploy) #5341

Description

@fbwe425

Feature Request

Summary

I'd love to see a first-party typed RPC client for Hono that works seamlessly in edge environments like Cloudflare Workers and Deno Deploy, without requiring Node.js-specific adapters.

Motivation

Currently, when building a full-stack app with Hono on Cloudflare Workers (using Wrangler + Vite), sharing the router type between server and client requires a custom setup. The hono/client package is great, but there are a few rough edges when targeting edge runtimes specifically:

  1. The client currently relies on fetch from the global scope — explicit environment-aware fetch injection would improve Workers compatibility (especially in test environments using Miniflare)
  2. No built-in support for streaming RPC responses (SSE / ReadableStream) in the typed client
  3. Error handling types are not propagated — HTTPException subtypes are lost on the client side

Proposed API

// server: app.ts
const app = new Hono()
  .get('/user/:id', async (c) => {
    return c.json({ id: c.req.param('id'), name: 'F. B. Weber' })
  })

export type AppType = typeof app

// client: anywhere (edge, browser, Node)
import { hc } from 'hono/client'
import type { AppType } from './app'

const client = hc<AppType>('https://api.example.com', {
  fetch: env.SERVICE_BINDING.fetch.bind(env.SERVICE_BINDING), // service binding support
})

const res = await client.user[':id'].$get({ param: { id: '42' } })
const data = await res.json() // fully typed

Additional Context

  • Cloudflare Workers Service Bindings expose a fetch-compatible interface — supporting this would enable zero-latency internal RPC without HTTP overhead
  • This would make Hono a natural fit for microservice architectures on Cloudflare (similar to what tRPC does for Next.js)
  • Related: Cloudflare Service Bindings docs

Would love to discuss the design. Happy to submit a PR if the direction is agreed upon!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions