API 文档
完整的 API 使用指南
基础 URL
https://api.olnk.cc认证
所有请求需要在 Header 中包含 API 密钥
X-Adapter-Key: <your-api-key>创建短链接
POST /v1/links
请求示例:
curl -X POST https://api.olnk.cc/v1/links \
-H "Content-Type: application/json" \
-H "X-Adapter-Key: your-api-key" \
-d '{
"url": "https://example.com",
"slug": "optional-slug",
"project_id": "infonity-core",
"tags": ["tag1", "tag2"],
"hide_referer": true
}'请求参数:
url(必需) - 目标 URLslug(可选) - 自定义短码project_id(可选) - 项目 ID,默认为 "infonity-core"tags(可选) - 标签数组hide_referer(可选) - 是否隐藏来源信息,默认使用项目设置expires_at(可选) - 过期时间 (RFC3339 格式)
响应示例:
{
"code": "abc123",
"short_url": "https://olnk.cc/abc123",
"long_url": "https://example.com",
"hide_referer": true,
"usage": {
"total_links": 10,
"daily_creates": 5,
"minute_remaining": 55
},
"limits": {
"total_links": 100,
"daily_creates": 50,
"per_minute_creates": 10
}
}项目管理
管理项目配置,包括隐私保护默认设置
创建/更新项目:
POST /v1/projects
curl -X POST https://api.olnk.cc/v1/projects \
-H "Content-Type: application/json" \
-H "X-Adapter-Key: your-api-key" \
-d '{
"id": "my-project",
"name": "我的项目",
"hide_referer": true
}'列出所有项目:
GET /v1/projects
curl -X GET https://api.olnk.cc/v1/projects \ -H "X-Adapter-Key: your-api-key"
获取项目详情:
GET /v1/projects/:id
curl -X GET https://api.olnk.cc/v1/projects/my-project \ -H "X-Adapter-Key: your-api-key"
删除项目:
DELETE /v1/projects/:id
curl -X DELETE https://api.olnk.cc/v1/projects/my-project \ -H "X-Adapter-Key: your-api-key"
获取链接信息
GET /v1/links/:code
curl -X GET https://api.olnk.cc/v1/links/abc123 \ -H "X-Adapter-Key: your-api-key"
获取统计信息
GET /v1/links/:code/stats
curl -X GET https://api.olnk.cc/v1/links/abc123/stats \ -H "X-Adapter-Key: your-api-key"
返回指定短链接的统计数据,包括点击次数、来源、国家等信息
列出链接
GET /v1/links
curl -X GET "https://api.olnk.cc/v1/links?project_id=my-project&limit=50&offset=0" \ -H "X-Adapter-Key: your-api-key"
查询参数:project_id (可选), tag (可选), limit (可选,默认50), offset (可选,默认0), order (可选)
健康检查
GET /healthz 或 GET /v1/healthz
curl https://api.olnk.cc/healthz
检查 API 服务状态,无需认证
使用示例
JavaScript/TypeScript:
const response = await fetch('https://api.olnk.cc/v1/links', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Adapter-Key': 'your-api-key'
},
body: JSON.stringify({
url: 'https://example.com',
project_id: 'my-project',
hide_referer: true
})
});
const data = await response.json();
console.log(data.short_url);Python:
import requests
response = requests.post(
'https://api.olnk.cc/v1/links',
headers={
'X-Adapter-Key': 'your-api-key',
'Content-Type': 'application/json'
},
json={
'url': 'https://example.com',
'project_id': 'my-project',
'hide_referer': True
}
)
data = response.json()
print(data['short_url'])