API 部署快速文档

返回首页

接口说明

部署入口:POST /api/deploy

内容协作:GET /api/deploy/content、PATCH /api/deploy/content

  • 请求头必须为 Content-Type: application/json
  • 请传 JSON 对象(filename + content + 可选 title)
  • 不要使用 curl -F file 或 multipart/form-data
  • 仅支持单个 HTML 请求,不支持批量部署
  • 可选开启自定义短链:enableCustomCode=true + customCode
  • 已知短链 code 或 url,可读取、下载、更新对应 HTML 内容
  • 每次部署成功后,全局冷却 10 秒
  • 冷却期间返回 429,并包含 retryAfterSeconds
  • 最大 HTML 体积 1 MB

请求示例

curl -X POST https://www.htmlcode.fun/api/deploy \
  -H "Content-Type: application/json" \
  -d '{
    "filename": "index.html",
    "title": "my-agent-page",
    "content": "<!doctype html><html><body><h1>Hello Agent</h1></body></html>"
  }'

自定义短链部署示例(默认关闭)

curl -X POST https://www.htmlcode.fun/api/deploy \
  -H "Content-Type: application/json" \
  -d '{
    "filename": "landing.html",
    "title": "my-landing",
    "content": "<!doctype html><html><body><h1>Landing</h1></body></html>",
    "enableCustomCode": true,
    "customCode": "my-site-01"
  }'

读取 HTML 内容

curl "https://www.htmlcode.fun/api/deploy/content?code=my-site-01"

下载 HTML 文件

curl -L "https://www.htmlcode.fun/api/deploy/content?code=my-site-01&download=1" -o page.html

更新 HTML 内容

curl -X PATCH https://www.htmlcode.fun/api/deploy/content \
  -H "Content-Type: application/json" \
  -d '{
    "code": "my-site-01",
    "content": "<!doctype html><html><body><h1>Updated</h1></body></html>",
    "title": "my-landing-v2",
    "filename": "landing-v2.html"
  }'

成功响应示例

{
  "success": true,
  "id": "uuid",
  "code": "abc123",
  "url": "https://www.htmlcode.fun/s/abc123",
  "qrCode": "https://.../qrcodes/abc123.png",
  "requestId": "uuid",
  "cooldownSeconds": 10,
  "nextAvailableAt": "2026-03-16T12:00:10.000Z"
}

冷却响应示例

{
  "success": false,
  "error": "当前处于部署冷却期,请稍后再试。",
  "errorCode": "COOLDOWN_ACTIVE",
  "detail": "部署成功后需等待 10 秒。",
  "stage": "rate_limit",
  "requestId": "uuid",
  "retryAfterSeconds": 7
}

常见错误调用(不要这样用)

curl -L -X POST https://www.htmlcode.fun/api/deploy -F "file=@index.html"

如果上传方式不正确,接口会返回结构化错误字段:errorCode、hint、docs、stage、detail、requestId。