Base URL: http://localhost:8080/api
Content-Type: application/json
GET /api/version响应示例:
{
"version": "1.0.0",
"wpl_version": "0.5.0",
"oml_version": "0.3.0"
}POST /api/debug/parse请求体:
{
"rules": "package /nginx/access { rule access_log { ... } }",
"logs": "192.168.1.1 - admin [2024-01-20] \"GET /api\" 200 1024"
}响应示例:
{
"success": true,
"fields": {
"client_ip": "192.168.1.1",
"user": "admin",
"timestamp": "2024-01-20",
"status": "200",
"size": "1024"
}
}POST /api/debug/transform请求体:
{
"rules": "name : /nginx/access/transform\nrule : /nginx/access*\n---\nsource_ip = take(option:[client_ip]) ;",
"fields": {
"client_ip": "192.168.1.1",
"user": "admin"
}
}响应示例:
{
"success": true,
"output": {
"source_ip": "192.168.1.1"
}
}GET /api/debug/examples响应示例:
{
"examples": [
{
"name": "nginx_access",
"wpl": "package /nginx/access { ... }",
"oml": "name : /nginx/access/transform ...",
"sample_log": "192.168.1.1 - admin ..."
}
]
}POST /api/debug/wpl/format请求体:
{
"rules": "package /nginx/access{rule access_log{(ip:client_ip)}}"
}响应示例:
{
"formatted": "package /nginx/access {\n rule access_log {\n (ip:client_ip)\n }\n}"
}POST /api/debug/oml/format请求体:
{
"rules": "name:/nginx/access/transform\nrule:/nginx/access*\n---\nsource_ip=take(option:[client_ip]);"
}响应示例:
{
"formatted": "name : /nginx/access/transform\n\nrule :\n /nginx/access*\n---\nsource_ip = take(option:[client_ip]) ;"
}POST /api/debug/decode/base64请求体:
{
"data": "SGVsbG8gV29ybGQ="
}响应示例:
{
"decoded": "Hello World"
}所有 API 在出错时返回统一的错误格式:
{
"success": false,
"error": "错误描述信息"
}HTTP 状态码:
200: 成功400: 请求参数错误500: 服务器内部错误
# 获取版本信息
curl -X GET http://localhost:8080/api/version
# WPL 解析
curl -X POST http://localhost:8080/api/debug/parse \
-H "Content-Type: application/json" \
-d '{
"rules": "package /nginx/access { rule access_log { (ip:client_ip) } }",
"logs": "192.168.1.1"
}'
# OML 转换
curl -X POST http://localhost:8080/api/debug/transform \
-H "Content-Type: application/json" \
-d '{
"rules": "name : /nginx/access/transform\nrule : /nginx/access*\n---\nsource_ip = take(option:[client_ip]) ;",
"fields": {"client_ip": "192.168.1.1"}
}'// 获取版本信息
const version = await fetch('http://localhost:8080/api/version')
.then(res => res.json());
// WPL 解析
const parseResult = await fetch('http://localhost:8080/api/debug/parse', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
rules: 'package /nginx/access { ... }',
logs: '192.168.1.1 ...'
})
}).then(res => res.json());