跳到正文

CDN

边缘内容分发、缓存清除(按路径、标签或全部)与交付统计,覆盖主流 CDN vendor。

概览

基础路径: https://api.infrai.cc/v1/cdn
鉴权头: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/cdn capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/cdn/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

方法

cdn.distribution.create

POST /v1/cdn/distribution/create

创建一个 CDN 分发(vendor 的 zone/service/域名),以边缘缓存前置源站,返回供你的主机名指向的 CNAME 目标。

参数

名称类型必填说明
originstring
必填
边缘前置的源站主机 / URL。
domainstring可选公开交付主机名(CNAME 目标)。
enabledboolean可选分发是否对外服务流量。
cache_ttl_secondsnumber可选默认边缘缓存 TTL(秒)。
allowed_methodsstring[]可选边缘转发的 HTTP 方法。
https_onlyboolean可选在边缘强制 HTTPS。
tagsstring[]可选缓存标签 / surrogate-key 标记。
vendorstring可选可选的显式 vendor 锁定;否则按区域解析。

返回

Distribution { distribution_id, origin, domain, enabled, status }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X POST https://api.infrai.cc/v1/cdn/distribution/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"origin": "..."}'

cdn.distribution.get

GET /v1/cdn/distribution/get/{distribution_id}

获取 CDN 分发的当前状态、边缘主机名与源站配置。

参数

名称类型必填说明
distribution_idstring
必填
分发 id。

返回

Distribution

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X GET https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

cdn.distribution.list

GET /v1/cdn/distribution/list

列出账户下的全部 CDN 分发。

参数

名称类型必填说明
cursorstring可选不透明分页游标。
limitnumber可选返回条目的最大数量。

返回

{ items: Distribution[], next_cursor?: string }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X GET https://api.infrai.cc/v1/cdn/distribution/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

cdn.distribution.update

PATCH /v1/cdn/distribution/update/{distribution_id}

更新 CDN 分发(启用 / 停用、源站、缓存设置)。

参数

名称类型必填说明
distribution_idstring
必填
分发 id。
originstring可选边缘前置的源站主机 / URL。
domainstring可选公开交付主机名(CNAME 目标)。
enabledboolean可选分发是否对外服务流量。
cache_ttl_secondsnumber可选默认边缘缓存 TTL(秒)。
allowed_methodsstring[]可选边缘转发的 HTTP 方法。
https_onlyboolean可选在边缘强制 HTTPS。
tagsstring[]可选缓存标签 / surrogate-key 标记。
vendorstring可选可选的显式 vendor 锁定;否则按区域解析。

返回

Distribution

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X PATCH https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"origin": "..."}'

cdn.distribution.delete

DELETE /v1/cdn/distribution/delete/{distribution_id}

删除 CDN 分发并拆除其边缘配置。

参数

名称类型必填说明
distribution_idstring
必填
分发 id。

返回

{ ok: boolean }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X DELETE https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

cdn.cache.purge

POST /v1/cdn/cache/purge

清除某分发的 CDN 边缘缓存——按路径、按缓存标签 / surrogate-key,或全部。计费工作动作。

参数

名称类型必填说明
distribution_idstring
必填
分发 id。
pathsstring[]可选要清除的具体 URL / 路径前缀。
tagsstring[]可选缓存标签 / surrogate-key 清除。
purge_everythingboolean可选清除整个缓存。
idempotency_keystring可选客户端提供的幂等键。
vendorstring可选可选的显式 vendor 锁定;否则按区域解析。

返回

{ ok: boolean, purge_id?: string }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X POST https://api.infrai.cc/v1/cdn/cache/purge \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"distribution_id": "..."}'

cdn.cache.stats

GET /v1/cdn/cache/stats

读取某分发的缓存分析:请求数、命中 / 未命中、命中率与已交付字节(驱动交付计费的计量出口)。

参数

名称类型必填说明
distribution_idstring可选分发 id。
fromstring可选统计时间范围起点。
tostring可选统计时间范围终点。

返回

{ requests, bytes_served, hit_ratio }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X GET https://api.infrai.cc/v1/cdn/cache/stats \
  -H "Authorization: Bearer $INFRAI_API_KEY"
高级:指定 vendor

默认情况下 infrai 会把每次调用智能路由到最佳可用供应商——无需自己挑选 vendor。作为高级逃生口,本能力支持可选的 vendor 入参以锁定某个供应商。本能力当前所有可用 vendor 可通过该能力 id 对应的 discovery 端点实时获取——参见 discovery API

GET /v1/discovery/{capability}

cdn.distribution.create

cdn.distribution.update

cdn.cache.purge

全部能力

本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。

能力端点说明
cdn.cache.purgePOST /v1/cdn/cache/purgePurge the CDN edge cache for a distribution — by path, by cache-tag/surrogate-key, or everything. Billable work-action.
cdn.cache.statsGET /v1/cdn/cache/statsRead cache analytics for a distribution: requests, hit/miss, hit ratio, and bytes delivered (the metered egress that drives delivery billing).
cdn.distribution.createPOST /v1/cdn/distribution/createCreate a CDN distribution (a vendor zone/service/domain) that fronts an origin with an edge cache, returning the CNAME target to point your hostname at.
cdn.distribution.deleteDELETE /v1/cdn/distribution/delete/{distribution_id}Delete a CDN distribution and tear down its edge configuration.
cdn.distribution.getGET /v1/cdn/distribution/get/{distribution_id}Fetch a CDN distribution's current state, edge hostname, and origin configuration.
cdn.distribution.listGET /v1/cdn/distribution/listList all CDN distributions on the account.
cdn.distribution.updatePATCH /v1/cdn/distribution/update/{distribution_id}Update a CDN distribution (enable/disable, origin, cache settings).

完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。

单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。

python
#!/usr/bin/env python3
"""Infrai · cdn — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://console.infrai.cc (Google/
GitHub sign-in grants $2 free credit). No SDK — the 12-line helper
below is the entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_pk_proj_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) cdn.distribution.create — POST /v1/cdn/distribution/create · Create a CDN distribution (a vendor zone/service/domain) that fronts an origin with an edge cache, returning the CNAME target to point your hostname at.
r1 = show("cdn.distribution.create", infrai("POST", "/v1/cdn/distribution/create", {"origin":"..."}))

# 2) cdn.cache.purge — POST /v1/cdn/cache/purge · Purge the CDN edge cache for a distribution — by path, by cache-tag/surrogate-key, or everything. Billable work-action.
r2 = show("cdn.cache.purge", infrai("POST", "/v1/cdn/cache/purge", {"distribution_id":"..."}))

# 3) cdn.distribution.list — GET /v1/cdn/distribution/list · List all CDN distributions on the account.
r3 = show("cdn.distribution.list", infrai("GET", "/v1/cdn/distribution/list"))