域名管理API

通过API接口管理CDN域名,实现自动化域名配置和管理

概述

域名管理API提供完整的域名CRUD操作,支持添加、查询、修改、删除域名,以及域名配置管理。

API基础URL:https://api.yakcdn.com/v1

API端点

获取域名列表

GET /domains

获取当前用户的所有域名列表

响应示例:

{
"code": 200,
"data": [
{
"id": "domain_123",
"domain": "example.com",
"status": "active",
"created_at": "2024-01-01T00:00:00Z"
}
]
}

添加域名

POST /domains

添加新的CDN域名

请求参数:

{
"domain": "example.com",
"origin": "192.168.1.100",
"origin_port": 80,
"origin_protocol": "http",
"cache_type": "web"
}

获取域名详情

GET /domains/{domain_id}

获取指定域名的详细信息

更新域名配置

PUT /domains/{domain_id}

更新域名的配置信息

删除域名

DELETE /domains/{domain_id}

删除指定的域名

请求示例

添加域名

curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"domain": "example.com",
"origin": "192.168.1.100",
"origin_port": 80,
"origin_protocol": "http",
"cache_type": "web"
}' \
https://api.yakcdn.com/v1/domains

Python示例

import requests
# 添加域名
def add_domain(domain, origin):
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
data = {
'domain': domain,
'origin': origin,
'origin_port': 80,
'origin_protocol': 'http',
'cache_type': 'web'
}
response = requests.post(
'https://api.yakcdn.com/v1/domains',
headers=headers,
json=data
)
return response.json()

响应格式

成功响应

{
"code": 200,
"message": "success",
"data": {...}
}

错误响应

{
"code": 400,
"message": "Invalid domain format",
"data": null
}

HTTP状态码

200 OK请求成功
201 Created资源创建成功
400 Bad Request请求参数错误
401 Unauthorized认证失败
404 Not Found资源不存在
500 Internal Server Error服务器内部错误

常见问题

Q: 域名添加失败怎么办?

A: 请检查域名格式是否正确,域名是否已完成备案,或联系技术支持。

Q: 如何批量管理域名?

A: 可以使用API接口批量操作,或编写脚本实现自动化管理。

Q: 域名状态有哪些?

A: 域名状态包括:pending(审核中)、active(正常)、suspended(暂停)、deleted(已删除)。

Q: API调用频率限制是多少?

A: 默认限制为每分钟100次请求,可以根据需要申请提高限制。

下一步

域名管理API学习完成后,建议您继续学习: