返回 Skill 列表
extension
分类: 开发与工程无需 API Key

Api Tester

执行结构化HTTP/HTTPS请求(GET、POST、PUT、DELETE),支持自定义标头和JSON正文。适用于API测试、健康检查或交互操作。

person作者: wanng-idehubclawhub

API Tester

A lightweight, dependency-free HTTP client for OpenClaw.

Usage

Basic GET Request

const api = require('skills/api-tester');
const result = await api.request('GET', 'https://api.example.com/data');
console.log(result.status, result.data);

POST Request with JSON Body

const api = require('skills/api-tester');
const payload = { key: 'value' };
const headers = { 'Authorization': 'Bearer <token>' };
const result = await api.request('POST', 'https://api.example.com/submit', headers, payload);

Return Format

The request function returns a Promise resolving to:

{
  status: 200,          // HTTP status code
  headers: { ... },     // Response headers
  data: { ... },        // Parsed JSON body (if applicable) or raw string
  raw: "...",           // Raw response body string
  error: "..."          // Error message if request failed (network error, timeout)
}

Features

  • Zero dependencies: Uses Node.js built-in http and https modules.
  • Auto-JSON: Automatically stringifies request body and parses response body if Content-Type matches.
  • Timeout support: Default 10s timeout, configurable.
  • Error handling: Returns structured error object instead of throwing, ensuring safe execution.