api-debuglisted
Install: claude install-skill afine907/skills
# API Debug — API 调试实战指南
从请求构造到问题定位的完整 API 调试技能。
## Goal
API 调试实战指南,包含请求构造、响应分析、问题定位、性能诊断、安全测试
## Trigger
- 用户要求"调试API"、"测试接口"
- API 返回异常需要排查
- 需要构造复杂请求
## 调试流程
```
问题描述 → 请求构造 → 发送请求 → 响应分析 → 问题定位 → 修复验证
```
## 请求构造
### curl 进阶用法
```bash
# 基础 GET
curl https://api.example.com/users
# POST JSON
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"张三","email":"zhangsan@example.com"}'
# 带认证
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
https://api.example.com/users/me
# Basic Auth
curl -u username:password https://api.example.com/admin
# 带 Cookie
curl -b "session=abc123" https://api.example.com/dashboard
# 文件上传
curl -X POST https://api.example.com/upload \
-F "file=@./photo.jpg" \
-F "description=Profile photo"
# 下载文件
curl -O https://api.example.com/files/report.pdf
# 超时设置
curl --connect-timeout 5 --max-time 30 https://api.example.com
# 重试
curl --retry 3 --retry-delay 2 https://api.example.com
# 保存响应头
curl -D headers.txt https://api.example.com
# 跟随重定向
curl -L https://api.example.com/redirect
# 忽略 SSL 证书(调试用)
curl -k https://self-signed.example.com
# 详细调试
curl -v https://api.example.com 2>&1 | head -50
```
### httpie 更友好
```bash
# GET
http https://api.example.com/users
# POST(自动 JSON)
http POST https://api.example.com/users \
name=张三 email=zhangsan@example.com
# 带认证
http -a username:pas