Hono

From G1Joshi/Agent-Skills · View interactive version

Hono is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Hono framework assistance covering ultra-fast routing, Web Standards, multi-runtime support (Cloudflare Workers, Deno, Bun, Node), and RPC. Use when developing edge APIs and lightweight microservices.

How to use this skill

Skill file

Hono

Hono (Japanese for "Flame") is a small, simple, and ultrafast web framework built on Web Standards. It runs anywhere: Cloudflare Workers, Fastly, Deno, Bun, Node.js, and Vercel.

When to Use

Quick Start

import { Hono } from "hono";
const app = new Hono();

app.get("/", (c) => c.text("Hello Hono!"));

app.get("/user/:name", (c) => {
  const name = c.req.param("name");
  return c.json({ message: `Hello ${name}!` });
});

export default app;

Core Concepts

Multi-Runtime API with RegExpRouter

Lightweight REST API with path parameter extraction:

import { Hono } from "hono";
import { logger } from "hono/logger";
import { cors } from "hono/cors";

const app = new Hono();

app.use("*", logger());
app.use("/api/*", cors());

app.get("/api/users/:id", (c) => {
  const id = c.req.param("id");
  const role = c.req.query("role") || "member";

  return c.json({
    id,
    role,
    runtime: "Cloudflare / Edge / Bun / Node",
    timestamp: Date.now(),
  });
});

export default app;

Type-Safe Request Validation with Zod Validator

Validating request bodies, headers, and query strings:

import { Hono } from "hono";
import { zValidator } from "@hono/zod-validator";
import { z } from "zod";

const app = new Hono();

const userSchema = z.object({
  username: z.string().min(3),
  email: z.string().email(),
  age: z.number().int().positive().optional(),
});

app.post("/api/users", zValidator("json", userSchema), (c) => {
  // c.req.valid('json') is fully typed according to userSchema
  const data = c.req.valid("json");
  return c.json({ success: true, user: data }, 201);
});

Hono RPC: Type-Safe Client Sharing

Exporting API routes for direct consumption in frontend clients:

// server.ts
import { Hono } from "hono";
const app = new Hono().get("/api/posts", (c) =>
  c.json([{ id: 1, title: "Hono Edge" }]),
);

export type AppType = typeof app;

// client.ts (In React / Next.js)
import { hc } from "hono/client";
import type { AppType } from "./server";

const client = hc<AppType>("https://api.example.com");
const res = await client.api.posts.$get();
const posts = await res.json(); // Fully typed!

Common Patterns

End-to-End Type-Safe RPC Client

Problem: Maintaining synchronized TypeScript API client contracts between edge backend and frontend.

Solution:

Export Hono AppType and consume with hono/client:

// server.ts
import { Hono } from "hono";
const app = new Hono().get("/api/user/:id", (c) => {
  return c.json({ id: c.req.param("id"), name: "Alice" });
});
export type AppType = typeof app;

// client.ts
import { hc } from "hono/client";
import type { AppType } from "./server";

const client = hc<AppType>("https://api.example.com");
const res = await client.api.user[":id"].$get({ param: { id: "123" } });
const data = await res.json(); // Strictly typed { id: string, name: string }

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :------------------------------------------------------ | :------------------------------------------------------------- | :-------------------------------------------------------------------------- |

| TypeError: c.req.json is not a function | Accessing body parsing as method rather than awaiting promise. | Use const body = await c.req.json(). |

| Route not matching on sub-path | Route prefix mismatch in app.route('/prefix', subApp). | Ensure subApp paths are relative to mount point (/ instead of /prefix). |

| Environment variables undefined on Cloudflare Workers | Accessing process.env instead of c.env. | Extract bindings from context: c.env.MY_KV_STORE. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.