hono-cloudflare
БесплатноБез исполняемых скриптовНе проверенHono on Cloudflare Workers - bindings, KV, D1, R2, Durable Objects, and edge deployment patterns
от bobmatnyc★ 79 звёзд на GitHubОб этом скилле
Hono on Cloudflare Workers
Overview
Hono was originally built for Cloudflare Workers and provides first-class support for the entire Cloudflare ecosystem including KV, D1, R2, Durable Objects, Queues, and more.
Key Features:
- Native Workers support
- Type-safe bindings access
- KV, D1, R2, Durable Objects integration
- Static asset serving
- Cloudflare Pages support
- Queue and scheduled handlers
When to Use This Skill
Use Hono on Cloudflare when:
- Building edge APIs with global distribution
- Need serverless SQLite with D1
- Building real-time apps with Durable Objects
- Storing files with R2
- Need fast key-value storage with KV
- Deploying full-stack apps to Pages
Quick Start
Create New Project
npm create hono@latest my-app
# Select: cloudflare-workers
cd my-app
npm install
npm run dev
Project Structure
my-app/
├── src/
│ └── index.ts # Main entry point
├── wrangler.toml # Cloudflare configuration
├── package.json
└── tsconfig.json
Basic Application
// src/index.ts
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => c.text('Hello Cloudflare Workers!'))
export default app
Deploy
# Deploy to Cloudflare
npx wrangler deploy
# Local development
npx wrangler dev
Environment Bindings
Typed Bindings
import { Hono } from 'hono'
// Define your bindings
type Bindings = {
// Environment variables
API_KEY: string
DATABASE_URL: string
// KV Namespaces
MY_KV: KVNamespace
// D1 Databases
DB: D1Database
// R2 Buckets
BUCKET: R2Bucket
// Durable Objects
COUNTER: DurableObjectNamespace
// Queues
MY_QUEUE: Queue
}
const app = new Hono<{ Bindings: Bindings }>()
app.get('/config', (c) => {
// Fully typed access
const apiKey = c.env.API_KEY
return c.json({ configured: !!apiKey })
})
export default app
wrangler.toml Configuration
name = "my-app"
main = "src/index.ts"
compatibility_date = "2024-01-01"
[vars]
API_KEY = "your-api-key" # pragma: allowlist secret
kv_namespaces
binding = "MY_KV"
id = "your-kv-id"
d1_databases
binding = "DB"
database_name = "my-database"
database_id = "your-d1-id"
r2_buckets
binding = "BUCKET"
bucket_name = "my-bucket"
queues.producers
binding = "MY_QUEUE"
queue = "my-queue"
KV Storage
Basic Operations
type Bindings = {
CACHE: KVNamespace
}
const app = new Hono<{ Bindings: Bindings }>()
// Get value
app.get('/cache/:key', async (c) => {
const key = c.req.param('key')
const value = await c.env.CACHE.get(key)
if (!value) {
return c.json({ error: 'Not found' }, 404)
}
return c.json({ key, value })
})
// Get JSON value
app.get('/cache/:key/json', async (c) => {
const key = c.req.param('key')
const value = await c.env.CACHE.get(key, 'json')
return c.json({ key, value })
})
// Set value
app.put('/cache/:key', async (c) => {
const key = c.req.param('key')
const body = await c.req.json()
await c.env.CACHE.put(key, JSON.stringify(body), {
expirationTtl: 3600 // 1 hour
})
return c.json({ success: true })
})
// Delete value
app.delete('/cache/:key', async (c) => {
const key = c.req.param('key')
await c.env.CACHE.delete(key)
return c.json({ success: true })
})
// List keys
app.get('/cache', async (c) => {
const prefix = c.req.query('prefix') || ''
const list = await c.env.CACHE.list({ prefix, limit: 100 })
return c.json({ keys: list.keys })
})
KV with Metadata
interface UserMeta {
createdAt: string
role: string
}
app.put('/users/:id', async (c) => {
const id = c.req.param('id')
const user = await c.req.json()
await c.env.CACHE.put(`user:${id}`, JSON.stringify(user), {
metadata: {
createdAt: new Date().toISOString(),
role: user.role
} as UserMeta
})
return c.json({ success: true })
})
app.get('/users/:id', async (c) => {
const id = c.req.param('id')
const { value, metadata } = await c.env.CACHE.getWithMetadata<UserMeta>(`user:${id}`, 'json')
if (!value) {
return c.json({ error: 'Not found' }, 404)
}
return c.json({ user: value, metadata })
})
D1 Database
Basic Queries
type Bindings = {
DB: D1Database
}
const app = new Hono<{ Bindings: Bindings }>()
// Select all
app.get('/users', async (c) => {
const { results } = await c.env.DB
.prepare('SELECT * FROM users ORDER BY created_at DESC')
.all()
return c.json({ users: results })
})
// Select one
app.get('/users/:id', async (c) => {
const id = c.req.param('id')
const user = await c.env.DB
.prepare('SELECT * FROM users WHERE id = ?')
.bind(id)
.first()
if (!user) {
return c.json({ error: 'Not found' }, 404)
}
return c.json({ user })
})
// Insert
app.post('/users', async (c) => {
const { name, email } = await c.req.json()
const result = await c.env.DB
.prepare('INSERT INTO users (name
Установить hono-cloudflare в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл hono-cloudflare?
Hono on Cloudflare Workers - bindings, KV, D1, R2, Durable Objects, and edge deployment patterns
Как установить скилл hono-cloudflare?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл hono-cloudflare запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic