api-tester

TotalClaw 作者 totalclaw

使用自定义标头和 JSON 正文支持执行结构化 HTTP/HTTPS 请求(GET、POST、PUT、DELETE)。用于 API 测试、运行状况检查或以编程方式与 REST 服务交互,而无需依赖curl。

安装 / 下载方式

TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~wanng-ide-api-tester
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~wanng-ide-api-tester/file -o wanng-ide-api-tester.md
## 概述(中文)

使用自定义标头和 JSON 正文支持执行结构化 HTTP/HTTPS 请求(GET、POST、PUT、DELETE)。用于 API 测试、运行状况检查或以编程方式与 REST 服务交互,而无需依赖curl。

## 原文

# API Tester

A lightweight, dependency-free HTTP client for OpenClaw.

## Usage

### Basic GET Request

```javascript
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

```javascript
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:

```javascript
{
  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.