API 文檔

完整的 RESTful API 文檔,讓您輕鬆整合短網址服務到您的應用程式中

登入管理後台 以查看需要身份驗證的 API 端點

快速開始

基本資訊

  • 基礎 URL: http://go-to.lol/api
  • 格式: JSON
  • 編碼: UTF-8
  • HTTP 方法: GET, POST, DELETE
GET

獲取短網址詳情

GET

獲取統計數據

程式碼範例

JavaScript

// 獲取短網址詳情
async function getLinkDetails(shortCode) {
    const response = await fetch(`/api/links/${shortCode}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
        }
    });
    
    const data = await response.json();
    return data;
}

// 使用範例
getLinkDetails('abc123')
    .then(data => {
        console.log('短網址詳情:', data);
        console.log('原始網址:', data.original_url);
        console.log('點擊次數:', data.click_count);
    })
    .catch(error => console.error('錯誤:', error));

Python

import requests

# 獲取短網址詳情
def get_link_details(short_code):
    response = requests.get(f'http://go-to.lol/api/links/{short_code}')
    return response.json()

# 獲取統計數據
def get_stats(short_code):
    response = requests.get(f'http://go-to.lol/api/links/{short_code}/stats')
    return response.json()

# 使用範例
try:
    details = get_link_details('abc123')
    print(f"原始網址: {details['original_url']}")
    print(f"點擊次數: {details['click_count']}")
    print(f"建立時間: {details['created_at']}")
except Exception as e:
    print(f"錯誤: {e}")

錯誤代碼

HTTP 狀態 錯誤類型 說明 解決方法
400 Bad Request 請求參數無效或缺少必要參數 檢查請求參數格式和內容
404 Not Found 請求的短網址不存在 確認短代碼是否正確
500 Internal Server Error 伺服器內部錯誤 請稍後重試或聯繫管理員