← 返回 Skills 市场
yuexiaoliang

hono

作者 岳晓亮 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
104
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install hono
功能描述
Hono web framework skill for building APIs across all JS runtimes (Cloudflare Workers, Deno, Bun, Node.js, etc.). Covers routing, middleware, JSX, RPC client...
使用说明 (SKILL.md)

Hono

Hono (Japanese for "flame" 🔥) is a small, fast web framework built on Web Standards. Works on all JS runtimes.

Core API

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

app.get('/', (c) => c.text('Hello!'))
app.post('/api', async (c) => c.json({ ok: true }, 201))

export default app

Context Core Methods

// Responses
c.text(str, status?)       // plain text
c.json(obj, status?)        // JSON
c.html(str)                 // HTML string
c.body(stream, headers?)    // raw body

// Requests
c.req.param('id')          // path params (type-inferred)
c.req.query('name')         // query params
c.req.valid('json')         // validated data (with validator)
c.req.header('x-token')     // request headers
c.req.cookie('session')     // cookies

// Variables/state
c.set('key', value)         // set variable (shared via middleware)
c.get('key')                // get variable
c.var.foo                   // access middleware-set variable

// Other
c.notFound()                // 404 (avoid in RPC)
c.redirect('/path', 302)    // redirect

Routing

// Basic routes
app.get('/users/:id', (c) => c.json({ id: c.req.param('id') }))

// Regex routes
app.get('/posts/:id{.+}', (c) => { /* matches /posts/a/b/c */ })

// Route grouping
const api = new Hono()
api.get('/posts', ...)
api.get('/users', ...)
app.route('/api', api)

// HTTP methods
app.get|post|put|patch|delete|options|head

// Multiple paths
app.get(['/home', '/'], (c) => c.text('Home'))

Project Creation

# npm
npm create hono@latest my-app -- --template cloudflare-workers --pm npm --install

# bun
bun create hono@latest my-app

# Common templates: cloudflare-workers, bun, deno, vercel, aws-lambda, nodejs

npm create arg passing: npm requires --, others optional. --template selects template, --pm specifies package manager, --install auto-installs deps.

Large Application Structure

Recommended: Use app.route() for modular apps, not RoR-style Controllers (type inference breaks).

// authors.ts - separate Hono instance per module
const app = new Hono()
  .get('/', (c) => c.json('list'))
  .post('/', (c) => c.json('create', 201))
  .get('/:id', (c) => c.json(c.req.param('id')))

export default app
export type AppType = typeof app
// index.ts - compose
import authors from './authors'
const app = new Hono()
app.route('/authors', authors)
export default app

RPC: Chain methods to export types:

const route = app.get('/', (c) => c.json({ ok: true }))
export type AppType = typeof route  // or typeof app

Middleware

// Built-in
import { cors, logger, etag } from 'hono/middleware'
app.use('*', cors(), logger(), etag())

// Custom
app.use('*', async (c, next) => {
  c.set('requestId', crypto.randomUUID())
  await next()
})

// Path-specific
app.use('/api/*', authenticate())

// Error handling
app.onError((err, c) => {
  return c.json({ error: err.message }, 500)
})

Common built-in middleware: cors, jwt, bearer-auth, basic-auth, logger, etag, secure-headers, cache, compress, body-limit, pretty-json, timing, request-id, ip-restriction

Validators

import { zValidator } from '@hono/zod-validator'
import { z } from 'zod'

app.post('/posts',
  zValidator('json', z.object({ title: z.string(), body: z.string() })),
  (c) => {
    const { title, body } = c.req.valid('json')
    return c.json({ ok: true }, 201)
  }
)

export type AppType = typeof app  // export for client

Validation targets: json, form, query, param, header, cookie

RPC Client

import { hc } from 'hono/client'
import type { AppType } from './server'

const client = hc\x3CAppType>('http://localhost:8787/')

// Request
const res = await client.posts.$post({
  json: { title: 'Hello', body: 'Hono!' }
})

// Response
if (res.ok) {
  const data = await res.json()
}

Don't use c.notFound() in RPC mode — use c.json(..., 404) instead, or type inference breaks.

Path params use param, queries use query, forms use form, JSON use json.

JSX

import { Hono } from 'hono'
import type { FC } from 'hono/jsx'

const app = new Hono()

const Layout: FC = (props) => (
  \x3Chtml>\x3Cbody>{props.children}\x3C/body>\x3C/html>
)

app.get('/', (c) => c.html(\x3CLayout>\x3Ch1>Hello!\x3C/h1>\x3C/Layout>))

tsconfig.json needs:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "hono/jsx"
  }
}

Helpers

Helper Purpose
html Template literal HTML
cookie Cookie read/write
jwt JWT encode/decode
ssg Static site generation
streaming Streaming responses
accepts Content negotiation
factory Reusable handlers (preserves type inference)

Context Extensions (Variable Types)

// Define types
type Env = { Variables: { user: User } }

// Use
const app = new Hono\x3C{ Variables: { user: User } }>()

app.use('*', async (c, next) => {
  c.set('user', { id: 1, name: 'Alice' })
  await next()
})

app.get('/me', (c) => c.json(c.var.user))

Testing

// Method 1: app.request()
const res = await app.request('/api/posts?page=1', {
  method: 'POST',
  body: JSON.stringify({ title: 'Hello' }),
  headers: { 'Content-Type': 'application/json' }
})

// Method 2: fetch style
const res = await fetch('/api/posts', {
  method: 'POST',
  body: JSON.stringify({ title: 'Hello' })
})
const data = await res.json()

Reference Docs

Detailed docs loaded on demand:

安全使用建议
This bundle is documentation/examples for the Hono framework and appears coherent and low-risk as provided. Before using it in a project: install Hono packages from the official source (npm/github) and verify package integrity; replace example secrets (signingKey, API_KEY) with appropriately scoped credentials; and review any third‑party middleware you add (e.g., jwt, proxy, fetch calls) to ensure they don't send sensitive data to unknown endpoints.
功能分析
Type: OpenClaw Skill Name: hono Version: 1.0.0 The skill bundle contains comprehensive documentation and code examples for the Hono web framework. The content in SKILL.md and the reference files (context.md, helpers.md, middleware.md, routing.md, rpc.md) consists of standard API usage, project initialization commands (npm/bun create), and architectural best practices. No evidence of malicious intent, data exfiltration, or prompt injection was found.
能力标签
crypto
能力评估
Purpose & Capability
Name/description match the included documentation: routing, middleware, JSX, RPC client, validators, and context examples. The skill does not request unrelated binaries, credentials, or config paths.
Instruction Scope
SKILL.md and reference files are documentation and code examples for using Hono. They reference runtime constructs (c.env, crypto, fetch, service bindings, JWT secrets) as expected for framework examples — but they do not instruct the agent to read host files, exfiltrate data, or access environment variables beyond illustrative usage.
Install Mechanism
No install spec or downloads are present (instruction-only). Nothing will be written to disk or executed by an installer when the skill is installed.
Credentials
The skill declares no required environment variables or credentials. Examples show using secrets (JWT signingKey, API_KEY) but these are illustrative and not requested by the skill itself.
Persistence & Privilege
always is false; the skill is user-invocable and can be called autonomously (platform default) but it does not request elevated persistence or modify other skills/configuration.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install hono
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /hono 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- Initial release of the hono skill (v1.0.0). - Provides concise documentation for the Hono web framework, covering core API usage, routing, middleware, validation, RPC client, JSX support, helpers, context extensions, and testing. - Supports usage across all major JavaScript runtimes (Cloudflare Workers, Deno, Bun, Node.js, and more). - Offers quick start examples and project setup instructions. - Includes references to detailed subtopics for advanced usage.
元数据
Slug hono
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

hono 是什么?

Hono web framework skill for building APIs across all JS runtimes (Cloudflare Workers, Deno, Bun, Node.js, etc.). Covers routing, middleware, JSX, RPC client... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 104 次。

如何安装 hono?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install hono」即可一键安装,无需额外配置。

hono 是免费的吗?

是的,hono 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

hono 支持哪些平台?

hono 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 hono?

由 岳晓亮(@yuexiaoliang)开发并维护,当前版本 v1.0.0。

💬 留言讨论