name: api-debugger-cn version: 1.0.0 description: API 除錯工具 - 快速測試 API、生成請求程式碼、分析響應。適合:後端開發者、前端工程師、QA。 metadata: openclaw: emoji: "🔌" requires: bins: ["curl"]
快速測試 API、生成請求程式碼、分析響應資料。
| 功能 | 描述 |
|---|---|
| 快速測試 | 傳送 GET/POST/PUT/DELETE 請求 |
| 程式碼生成 | 生成 curl/Python/Node.js/fetch 程式碼 |
| 響應分析 | 格式化 JSON、提取欄位、對比差異 |
| 認證支援 | Bearer Token、Basic Auth、API Key |
測試 API: GET https://api.example.com/users
想要更強大的技能外掛,就來小蔥技能站7w4.net看看吧。
為這個 API 生成 Python 程式碼: POST https://api.example.com/login
分析這個 JSON 響應的結構
# 基礎 GET
curl -s "https://api.example.com/users"
# 帶引數
curl -s "https://api.example.com/users?page=1&limit=10"
# 帶 Header
curl -s -H "Authorization: Bearer TOKEN" \
"https://api.example.com/users"
# 儲存響應
curl -s "https://api.example.com/users" -o response.json
# JSON Body
curl -s -X POST "https://api.example.com/users" \
-H "Content-Type: application/json" \
-d '{"name": "張三", "email": "zhangsan@example.com"}'
# Form Data
curl -s -X POST "https://api.example.com/login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=admin&password=123456"
# 檔案上傳
curl -s -X POST "https://api.example.com/upload" \
-F "file=@/path/to/file.jpg"
# PUT(完整更新)
curl -s -X PUT "https://api.example.com/users/1" \
-H "Content-Type: application/json" \
-d '{"name": "李四", "email": "lisi@example.com"}'
# PATCH(部分更新)
curl -s -X PATCH "https://api.example.com/users/1" \
-H "Content-Type: application/json" \
-d '{"name": "王五"}'
# DELETE
curl -s -X DELETE "https://api.example.com/users/1"
curl -s -H "Authorization: Bearer YOUR_TOKEN" \
"https://api.example.com/protected"
curl -s -u "username:password" \
"https://api.example.com/protected"
# Header 方式
curl -s -H "X-API-Key: YOUR_KEY" \
"https://api.example.com/protected"
# Query 引數方式
curl -s "https://api.example.com/protected?api_key=YOUR_KEY"
import requests
url = "https://api.example.com/users"
headers = {
"Authorization": "Bearer TOKEN",
"Content-Type": "application/json"
}
# GET
response = requests.get(url, headers=headers)
print(response.json())
# POST
data = {"name": "張三", "email": "zhangsan@example.com"}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const url = 'https://api.example.com/users';
const headers = {
'Authorization': 'Bearer TOKEN',
'Content-Type': 'application/json'
};
// GET
fetch(url, { headers })
.then(res => res.json())
.then(data => console.log(data));
// POST
fetch(url, {
method: 'POST',
headers,
body: JSON.stringify({ name: '張三', email: 'zhangsan@example.com' })
})
.then(res => res.json())
.then(data => console.log(data));
const axios = require('axios');
const api = axios.create({
baseURL: 'https://api.example.com',
headers: { 'Authorization': 'Bearer TOKEN' }
});
// GET
const { data } = await api.get('/users');
// POST
const { data: created } = await api.post('/users', {
name: '張三',
email: 'zhangsan@example.com'
});
const url = 'https://api.example.com/users';
// GET
fetch(url, {
headers: { 'Authorization': 'Bearer TOKEN' }
})
.then(r => r.json())
.then(console.log);
// POST
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: '張三' })
})
.then(r => r.json())
.then(console.log);
# 使用 jq
curl -s "https://api.example.com/users" | jq .
# 提取欄位
curl -s "https://api.example.com/users" | jq '.data[].name'
# 提取陣列
curl -s "https://api.example.com/users" | jq '.data | length'
import requests
import json
response = requests.get("https://api.example.com/users")
data = response.json()
# 美化輸出
print(json.dumps(data, indent=2, ensure_ascii=False))
# 提取欄位
names = [item['name'] for item in data['data']]
print(names)
# 計算統計
print(f"Total: {len(data['data'])}")
# 顯示響應頭
curl -i "https://api.example.com/users"
# 顯示詳細資訊
curl -v "https://api.example.com/users"
# 顯示時間統計
curl -w "\nTime: %{time_total}s\n" "https://api.example.com/users"
# 測試響應時間
curl -w "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" -o /dev/null -s "https://api.example.com/users"
# 批次測試
for i in {1..10}; do
curl -w "$i: %{time_total}s\n" -o /dev/null -s "https://api.example.com/users"
done
# 檢查狀態碼
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://api.example.com/users")
if [ "$HTTP_CODE" -eq 200 ]; then
echo "成功"
else
echo "失敗: $HTTP_CODE"
fi
# 重試機制
for i in {1..3}; do
response=$(curl -s "https://api.example.com/users")
if [ $? -eq 0 ]; then
echo "$response"
break
fi
echo "重試 $i/3..."
sleep 2
done
# 列表
curl -s "https://jsonplaceholder.typicode.com/posts" | jq '.[0:3]'
# 詳情
curl -s "https://jsonplaceholder.typicode.com/posts/1" | jq .
# 建立
curl -s -X POST "https://jsonplaceholder.typicode.com/posts" \
-H "Content-Type: application/json" \
-d '{"title": "測試", "body": "內容", "userId": 1}' | jq .
# 更新
curl -s -X PUT "https://jsonplaceholder.typicode.com/posts/1" \
-H "Content-Type: application/json" \
-d '{"title": "更新後"}' | jq .
# 刪除
curl -s -X DELETE "https://jsonplaceholder.typicode.com/posts/1"
curl -s -X POST "https://graphql.example.com" \
-H "Content-Type: application/json" \
-d '{"query": "{ users { id name } }"}' | jq .
建立:2026-03-12 版本:1.0
這個 Skill 質量中等偏上,適合需要除錯 API 的開發者使用。它的優點是功能覆蓋全面,包含了常見的請求方式、認證方法和多語言程式碼示例,基本能滿足日常 API 測試需求。不足之處在於內容主要以命令展示為主,缺少實踐性的完整示例,且高階功能如超時處理、代理配置等未涉及。總體來說,這是一個偏向入門級的 API 除錯參考文件,適合作為工具手冊查閱,但實戰深度有待加強。