闲社服务运行正常AI智能体自动化平台
a

API测试工具

技能标识:api-tester

Test REST APIs with customizable headers, authentication, and request bodies. Use when debugging API endpoints, testing authentication flows, validating responses, or automating API checks. Supports GET, POST, PUT, DELETE, PATCH methods with JSON, form-data, and raw body formats. Ideal for developers testing webhooks, microservices, and third-party integrations.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
1
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

API测试工具

API 测试器

使用自定义标头、身份验证和请求体测试 REST API。

使用场景

  • - 开发过程中调试 API 端点
  • 测试身份验证流程
  • 验证 Webhook 负载
  • 检查 API 响应时间
  • 自动化健康检查
  • 测试第三方集成

快速入门

简单 GET 请求

python
import requests

def test_get(url, headers=None):
测试 GET 端点
try:
response = requests.get(url, headers=headers, timeout=30)
return {
status: response.status_code,
headers: dict(response.headers),
body: response.json() if response.headers.get(content-type, ).startswith(application/json) else response.text,
time: response.elapsed.total_seconds()
}
except Exception as e:
return {error: str(e)}

使用示例

test_get(https://api.github.com/users/octocat)

带 JSON 体的 POST 请求

python
def test_post(url, data, headers=None):
测试带 JSON 体的 POST 端点
default_headers = {Content-Type: application/json}
if headers:
default_headers.update(headers)

try:
response = requests.post(
url,
json=data,
headers=default_headers,
timeout=30
)
return {
status: response.status_code,
body: response.json() if response.headers.get(content-type, ).startswith(application/json) else response.text
}
except Exception as e:
return {error: str(e)}

使用示例

test_post(https://httpbin.org/post, {key: value})

带身份验证的测试

python
def testwithauth(url, token=None, username=None, password=None):
使用 Bearer 令牌或基本身份验证测试 API
headers = {}

if token:
headers[Authorization] = fBearer {token}
elif username and password:
import base64
credentials = base64.b64encode(f{username}:{password}.encode()).decode()
headers[Authorization] = fBasic {credentials}

return test_get(url, headers)

Bearer 令牌

testwithauth(https://api.example.com/data, token=yourtokenhere)

基本身份验证

testwithauth(https://api.example.com/data, username=admin, password=secret)

完整 API 测试套件

python
def comprehensiveapitest(base_url, endpoints):
测试多个端点
results = {}

for endpoint, config in endpoints.items():
url = f{base_url}{config[path]}
method = config.get(method, GET)
headers = config.get(headers, {})
data = config.get(data)

try:
if method == GET:
response = requests.get(url, headers=headers, timeout=30)
elif method == POST:
response = requests.post(url, json=data, headers=headers, timeout=30)
elif method == PUT:
response = requests.put(url, json=data, headers=headers, timeout=30)
elif method == DELETE:
response = requests.delete(url, headers=headers, timeout=30)

results[endpoint] = {
status: response.status_code,
success: 200 <= response.status_code < 300,
time: response.elapsed.total_seconds()
}
except Exception as e:
results[endpoint] = {error: str(e), success: False}

return results

使用示例

endpoints = { health: {path: /health, method: GET}, create_user: {path: /users, method: POST, data: {name: Test}}, get_user: {path: /users/1, method: GET} }

comprehensiveapitest(https://api.example.com, endpoints)

常见测试场景

Webhook 测试

python
from flask import Flask, request

def createwebhooklistener(port=5000):
创建本地 webhook 接收器用于测试
app = Flask(name)
received_data = []

@app.route(/webhook, methods=[POST])
def webhook():
data = request.json
received_data.append(data)
print(f收到 webhook: {data})
return {status: ok}

@app.route(/received, methods=[GET])
def get_received():
return {data: received_data}

return app

运行: app.run(port=5000)

使用 ngrok 暴露: ngrok http 5000

性能测试

python
import time

def testapiperformance(url, iterations=10):
测试 API 响应时间
times = []

for _ in range(iterations):
start = time.time()
requests.get(url, timeout=30)
times.append(time.time() - start)

return {
min: min(times),
max: max(times),
avg: sum(times) / len(times),
times: times
}

响应验证

python
def validateresponse(response, expectedstatus=200, required_fields=None):
验证 API 响应结构
errors = []

if response.get(status) != expected_status:
errors.append(f期望状态码 {expected_status},实际得到 {response.get(status)})

body = response.get(body, {})
if required_fields:
for field in required_fields:
if field not in body:
errors.append(f缺少必填字段: {field})

return {
valid: len(errors) == 0,
errors: errors
}

依赖项

bash
pip install requests flask

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 rest-api-tester-1776276468 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 rest-api-tester-1776276468 技能

通过命令行安装

skillhub install rest-api-tester-1776276468

下载

⬇ 下载 api-tester v1.0.0(免费)

文件大小: 2.53 KB | 发布时间: 2026-4-16 16:17

v1.0.0 最新 2026-4-16 16:17
Initial release
返回顶部