CDN
边缘内容分发、缓存清除(按路径、标签或全部)与交付统计,覆盖主流 CDN vendor。
概览
https://api.infrai.cc/v1/cdnAuthorization: Bearer $INFRAI_API_KEY# 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
创建一个 CDN 分发(vendor 的 zone/service/域名),以边缘缓存前置源站,返回供你的主机名指向的 CNAME 目标。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
origin | string | 必填 | 边缘前置的源站主机 / URL。 |
domain | string | 可选 | 公开交付主机名(CNAME 目标)。 |
enabled | boolean | 可选 | 分发是否对外服务流量。 |
cache_ttl_seconds | number | 可选 | 默认边缘缓存 TTL(秒)。 |
allowed_methods | string[] | 可选 | 边缘转发的 HTTP 方法。 |
https_only | boolean | 可选 | 在边缘强制 HTTPS。 |
tags | string[] | 可选 | 缓存标签 / surrogate-key 标记。 |
vendor | string | 可选 | 可选的显式 vendor 锁定;否则按区域解析。 |
返回
Distribution { distribution_id, origin, domain, enabled, status }示例
一次性前置(每个范例都假定已完成):
# 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_..."curl -X POST https://api.infrai.cc/v1/cdn/distribution/create \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"origin": "..."}'import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cdn/distribution/create",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'origin': '...'},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cdn.distribution.get
获取 CDN 分发的当前状态、边缘主机名与源站配置。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
distribution_id | string | 必填 | 分发 id。 |
返回
Distribution示例
一次性前置(每个范例都假定已完成):
# 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_..."curl -X GET https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID \
-H "Authorization: Bearer $INFRAI_API_KEY"import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cdn.distribution.list
列出账户下的全部 CDN 分发。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cursor | string | 可选 | 不透明分页游标。 |
limit | number | 可选 | 返回条目的最大数量。 |
返回
{ items: Distribution[], next_cursor?: string }示例
一次性前置(每个范例都假定已完成):
# 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_..."curl -X GET https://api.infrai.cc/v1/cdn/distribution/list \
-H "Authorization: Bearer $INFRAI_API_KEY"import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cdn/distribution/list",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cdn.distribution.update
更新 CDN 分发(启用 / 停用、源站、缓存设置)。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
distribution_id | string | 必填 | 分发 id。 |
origin | string | 可选 | 边缘前置的源站主机 / URL。 |
domain | string | 可选 | 公开交付主机名(CNAME 目标)。 |
enabled | boolean | 可选 | 分发是否对外服务流量。 |
cache_ttl_seconds | number | 可选 | 默认边缘缓存 TTL(秒)。 |
allowed_methods | string[] | 可选 | 边缘转发的 HTTP 方法。 |
https_only | boolean | 可选 | 在边缘强制 HTTPS。 |
tags | string[] | 可选 | 缓存标签 / surrogate-key 标记。 |
vendor | string | 可选 | 可选的显式 vendor 锁定;否则按区域解析。 |
返回
Distribution示例
一次性前置(每个范例都假定已完成):
# 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_..."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": "..."}'import os, requests
resp = requests.patch(
"https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'origin': '...'},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cdn.distribution.delete
删除 CDN 分发并拆除其边缘配置。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
distribution_id | string | 必填 | 分发 id。 |
返回
{ ok: boolean }示例
一次性前置(每个范例都假定已完成):
# 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_..."curl -X DELETE https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID \
-H "Authorization: Bearer $INFRAI_API_KEY"import os, requests
resp = requests.delete(
"https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cdn.cache.purge
清除某分发的 CDN 边缘缓存——按路径、按缓存标签 / surrogate-key,或全部。计费工作动作。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
distribution_id | string | 必填 | 分发 id。 |
paths | string[] | 可选 | 要清除的具体 URL / 路径前缀。 |
tags | string[] | 可选 | 缓存标签 / surrogate-key 清除。 |
purge_everything | boolean | 可选 | 清除整个缓存。 |
idempotency_key | string | 可选 | 客户端提供的幂等键。 |
vendor | string | 可选 | 可选的显式 vendor 锁定;否则按区域解析。 |
返回
{ ok: boolean, purge_id?: string }示例
一次性前置(每个范例都假定已完成):
# 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_..."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": "..."}'import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cdn/cache/purge",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'distribution_id': '...'},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/purge",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"distribution_id": "..."}),
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/purge",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"distribution_id": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cdn.cache.stats
读取某分发的缓存分析:请求数、命中 / 未命中、命中率与已交付字节(驱动交付计费的计量出口)。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
distribution_id | string | 可选 | 分发 id。 |
from | string | 可选 | 统计时间范围起点。 |
to | string | 可选 | 统计时间范围终点。 |
返回
{ requests, bytes_served, hit_ratio }示例
一次性前置(每个范例都假定已完成):
# 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_..."curl -X GET https://api.infrai.cc/v1/cdn/cache/stats \
-H "Authorization: Bearer $INFRAI_API_KEY"import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cdn/cache/stats",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/stats",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/stats",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);高级:指定 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.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. |
cdn.cache.stats | GET /v1/cdn/cache/stats | Read cache analytics for a distribution: requests, hit/miss, hit ratio, and bytes delivered (the metered egress that drives delivery billing). |
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. |
cdn.distribution.delete | DELETE /v1/cdn/distribution/delete/{distribution_id} | Delete a CDN distribution and tear down its edge configuration. |
cdn.distribution.get | GET /v1/cdn/distribution/get/{distribution_id} | Fetch a CDN distribution's current state, edge hostname, and origin configuration. |
cdn.distribution.list | GET /v1/cdn/distribution/list | List all CDN distributions on the account. |
cdn.distribution.update | PATCH /v1/cdn/distribution/update/{distribution_id} | Update a CDN distribution (enable/disable, origin, cache settings). |
完整示例
本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。
单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。
#!/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"))
一次性前置(每个范例都假定已完成):
# 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_..."# 1) Auth: every call is a raw HTTPS request to the Infrai gateway carrying
# only your project key. No SDK, no install.
# Get your key: sign in with Google/GitHub at the console for a project key
# + $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_..." # from the console
# 2) cdn.distribution.create
curl -X POST https://api.infrai.cc/v1/cdn/distribution/create \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"origin": "..."}'
# 3) cdn.distribution.get
curl -X GET https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 4) cdn.distribution.list
curl -X GET https://api.infrai.cc/v1/cdn/distribution/list \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 5) cdn.distribution.update
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": "..."}'
# 6) cdn.distribution.delete
curl -X DELETE https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 7) cdn.cache.purge
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": "..."}'
# 8) cdn.cache.stats
curl -X GET https://api.infrai.cc/v1/cdn/cache/stats \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 1) Auth: every call is a raw HTTPS request carrying only your project key.
# No SDK to install — just the `requests` library.
import os, requests
BASE = "https://api.infrai.cc"
HEADERS = {
"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}",
"Content-Type": "application/json",
}
# 2) cdn.distribution.create
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cdn/distribution/create",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'origin': '...'},
)
resp.raise_for_status()
print(resp.json())
# 3) cdn.distribution.get
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
# 4) cdn.distribution.list
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cdn/distribution/list",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
# 5) cdn.distribution.update
import os, requests
resp = requests.patch(
"https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'origin': '...'},
)
resp.raise_for_status()
print(resp.json())
# 6) cdn.distribution.delete
import os, requests
resp = requests.delete(
"https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
# 7) cdn.cache.purge
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cdn/cache/purge",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'distribution_id': '...'},
)
resp.raise_for_status()
print(resp.json())
# 8) cdn.cache.stats
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cdn/cache/stats",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
// 1) Auth: every call is a raw HTTPS request carrying only your project key.
// No SDK to install — just the built-in fetch().
const BASE = "https://api.infrai.cc";
const HEADERS = {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
};
// 2) cdn.distribution.create
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
console.log(await resp.json());
// 3) cdn.distribution.get
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 4) cdn.distribution.list
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 5) cdn.distribution.update
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
console.log(await resp.json());
// 6) cdn.distribution.delete
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 7) cdn.cache.purge
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/purge",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"distribution_id": "..."}),
},
);
console.log(await resp.json());
// 8) cdn.cache.stats
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/stats",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 1) Auth: every call is a raw HTTPS request carrying only your project key.
// No SDK to install — just the built-in fetch(), typed.
const BASE = "https://api.infrai.cc";
const HEADERS: Record<string, string> = {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
};
// 2) cdn.distribution.create
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 3) cdn.distribution.get
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 4) cdn.distribution.list
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 5) cdn.distribution.update
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"origin": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 6) cdn.distribution.delete
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 7) cdn.cache.purge
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/purge",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"distribution_id": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 8) cdn.cache.stats
const resp = await fetch(
"https://api.infrai.cc/v1/cdn/cache/stats",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);