惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
量子位
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
美团技术团队
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
罗磊的独立博客
Jina AI
Jina AI
小众软件
小众软件
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
博客园 - 聂微东
博客园_首页
The Cloudflare Blog
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Hono RPC with React Monorepo Template
Vladimir Vov · 2026-05-15 · via DEV Community

Hono RPC is a built-in feature of the Hono web framework that enables end‑to‑end type safety between your backend API and frontend client by automatically sharing and synchronising API specifications—without any code generation.

Let's see how we can create a monorepo with Hono API and a React app.

Monorepo

First, we need to create a folder for our new monorepo.

mkdir hono-rpc-and-react-monorepo
cd hono-rpc-and-react-monorepo

Enter fullscreen mode Exit fullscreen mode

Check that we have the latest pnpm installed.

npm i -g pnpm@latest

Enter fullscreen mode Exit fullscreen mode

Init new project.

pnpm init

Enter fullscreen mode Exit fullscreen mode

Add the pnpm-workspace.yaml workspace configuration file.

packages:
  - 'api'
  - 'web'

Enter fullscreen mode Exit fullscreen mode

Hono

Now we can create an empty Hono project.

pnpm create hono@latest api

Enter fullscreen mode Exit fullscreen mode

We need to update the api/package.json.

{
  "name": "@repo/api",
  "type": "module",
  "main": "src/index.ts",
  "scripts": {
    "dev": "tsx watch src/index.ts",
    "build": "tsc --build",
    "start": "node dist/index.js"
  },
  "dependencies": {
    "@hono/node-server": "^1.19.14",
    "hono": "^4.12.18"
  },
  "devDependencies": {
    "@types/node": "^20.11.17",
    "tsx": "^4.7.1",
    "typescript": "^5.8.3"
  }
}

Enter fullscreen mode Exit fullscreen mode

The name and build props were changed, and the main prop was added.

Let's export the hono application type from api/src/index.ts. We will need it to create a hono client inside our React app.

import { serve } from '@hono/node-server'
import { Hono } from 'hono'

const app = new Hono()
  .get('/api', (c) => {
    return c.text('Hello Hono!')
  })

export type AppType = typeof app

serve({
  fetch: app.fetch,
  port: 3000
}, (info) => {
  console.log(`Server is running on http://localhost:${info.port}`)
})

Enter fullscreen mode Exit fullscreen mode

Notice we are adding route handlers to the new Hono() object itself, so TypeScript could figure out the correct types for the hono client. Also, we changed the route from / to /api.

React

Let's create a Vite React project.

pnpm create vite

Enter fullscreen mode Exit fullscreen mode

Now we need to install hono.

pnpm i hono

Enter fullscreen mode Exit fullscreen mode

And add @repo/api as a development dependency to the web/package.json.

...
  "devDependencies": {
    "@repo/api": "workspace:*",
    ...

Enter fullscreen mode Exit fullscreen mode

Install added dependency.

pnpm i

Enter fullscreen mode Exit fullscreen mode

Let's update the web/vite.config.ts, so it would proxy all requests to our api in the development mode (add the server prop).

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true
      }
    }
  }
})

Enter fullscreen mode Exit fullscreen mode

Now we can add a hono client to the web/src/App.tsx.

...
import { hc } from 'hono/client'
import type { AppType } from '@repo/api'

const client = hc<AppType>('/')

function App() {
  const [count, setCount] = useState('')

  useEffect(() => {
    const fetchData = async () => {
      const res = await client.index.$get()
      if (res.ok) {
        const data = await res.text()
        setCount(data)
      }
    }

    fetchData()
  }, [])
  ...

Enter fullscreen mode Exit fullscreen mode

Test Time

Let's add one command to the root package.json to run both the api and web in development.

...
  "scripts": {
    "dev": "pnpm run --parallel dev"
  ...

Enter fullscreen mode Exit fullscreen mode

Now we can start our backend and frontend apps with one command.

pnpm dev

Enter fullscreen mode Exit fullscreen mode

Open your favorite web browser and navigate to http://localhost:5173. You will see the default Vite React page with Count is Hello Hono! text. The Hello Hono! was successfully fetched from our api. 🎉

Please check the repo and happy hacking! 💻

Credits

Photo by Janis Ringli on Unsplash