其他网站可以通过以下方式调用 API 生成短链:
fetch('YOUR_WORKER_URL/api/links', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
body: JSON.stringify({
url: 'https://example.com/long-url'
})
})
.then(r => r.json())
.then(data => {
console.log(data.shortUrl); // 短链地址
})
响应示例:{ "code": "aB3xYz", "shortUrl": "https://.../aB3xYz", "url": "...", "createdAt": "..." }