AutoAlg API

开发者工具 RESTful API — JSON 格式化、Base64 编解码、Hash 计算、URL 编码、时间戳转换、JWT 解码、UUID 生成等,一个 API Key 搞定。

Base URL: https://api.autoalg.com
版本: v1
认证: API Key

🔐 认证方式

所有 /v1/* 端点需要通过 X-API-Key 请求头进行认证。根路径 //health 无需认证。

在请求头中添加你的 API Key:

X-API-Key: ak_your_api_key_here

未认证的请求将返回 401 错误:

{"detail": "Invalid or missing API key"}

📡 API 端点

GET /health 服务健康检查

无需认证

{"status": "ok", "timestamp": 1741664830}
POST /v1/json JSON 格式化 / 压缩 / 验证
参数类型必填说明
datastring必填JSON 字符串
actionstring可选format | minify | validate,默认 format
indentint可选缩进空格数 (0-8),默认 2
curl -X POST https://api.autoalg.com/v1/json \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"data": "{\"name\":\"test\"}", "action": "format"}'
// 响应
{"result": "{\n  \"name\": \"test\"\n}"}
POST /v1/base64 Base64 编码 / 解码
参数类型必填说明
datastring必填要编码的文本或要解码的 Base64 字符串
actionstring可选encode | decode,默认 encode
curl -X POST https://api.autoalg.com/v1/base64 \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"data": "Hello AutoAlg", "action": "encode"}'
// 响应
{"result": "SGVsbG8gQXV0b0FsZw=="}
POST /v1/url URL 编码 / 解码
参数类型必填说明
datastring必填要编码/解码的字符串
actionstring可选encode | decode,默认 encode
curl -X POST https://api.autoalg.com/v1/url \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"data": "hello world&foo=bar", "action": "encode"}'
// 响应
{"result": "hello%20world%26foo%3Dbar"}
POST /v1/hash Hash 摘要计算
参数类型必填说明
datastring必填要计算 Hash 的文本
algorithmsstring[]可选算法列表,支持 md5/sha1/sha224/sha256/sha384/sha512,默认全部
curl -X POST https://api.autoalg.com/v1/hash \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"data": "hello world", "algorithms": ["md5", "sha256"]}'
// 响应
{
  "results": {
    "md5": "5eb63bbbe01eeed093cb22bb8f5acdc3",
    "sha256": "b94d27b9934d3e08a52e52d7da7dabfa..."
  }
}
POST /v1/timestamp 时间戳 ↔ 日期转换
参数类型必填说明
actionstring必填now | to_date | to_timestamp
valuestring条件时间戳或日期字符串 (to_date/to_timestamp 时必填)
unitstring可选s | ms,默认 s
curl -X POST https://api.autoalg.com/v1/timestamp \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"action": "now"}'
// 响应
{
  "timestamp_s": 1741664830,
  "timestamp_ms": 1741664830000,
  "iso": "2026-03-11T02:07:10+00:00",
  "utc": "2026-03-11 02:07:10 UTC"
}
POST /v1/jwt JWT Token 解码
参数类型必填说明
tokenstring必填JWT token 字符串
// 响应
{
  "header": {"alg": "HS256", "typ": "JWT"},
  "payload": {"sub": "1234", "name": "test", "iat": 1516239022}
}
POST /v1/uuid UUID v4 生成
参数类型必填说明
countint可选生成数量 (1-100),默认 1
uppercasebool可选大写输出,默认 false
no_hyphensbool可选去除连字符,默认 false
curl -X POST https://api.autoalg.com/v1/uuid \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"count": 3}'
// 响应
{"results": ["a1b2c3d4-...", "e5f6a7b8-...", "c9d0e1f2-..."]}
POST /v1/yaml YAML ↔ JSON 转换
参数类型必填说明
datastring必填YAML 或 JSON 字符串
actionstring可选yaml_to_json | json_to_yaml,默认 yaml_to_json
curl -X POST https://api.autoalg.com/v1/yaml \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"data": "name: test\nversion: 1", "action": "yaml_to_json"}'
// 响应
{"result": "{\n  \"name\": \"test\",\n  \"version\": 1\n}"}
POST /v1/sql SQL 格式化 / 压缩
参数类型必填说明
datastring必填SQL 语句
actionstring可选format | minify,默认 format
keyword_casestring可选upper | lower | capitalize,默认 upper
indent_widthint可选缩进宽度 (0-8),默认 2
POST /v1/regex 正则表达式匹配
参数类型必填说明
patternstring必填正则表达式
textstring必填待匹配文本
flagsstring可选标志: i (忽略大小写) m (多行) s (dotall)
// 响应
{
  "pattern": "\\d+",
  "match_count": 2,
  "matches": [
    {"match": "123", "start": 0, "end": 3, "groups": []},
    {"match": "456", "start": 5, "end": 8, "groups": []}
  ]
}
POST /v1/diff 文本差异对比
参数类型必填说明
text1string必填原始文本
text2string必填修改后文本
// 响应
{
  "diff": "--- original\n+++ modified\n...",
  "lines_added": 2,
  "lines_removed": 1
}

⚡ 快速上手

cURL

# 格式化 JSON
curl -X POST https://api.autoalg.com/v1/json \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"data": "{\"a\":1,\"b\":2}", "action": "format"}'

Python

import requests

resp = requests.post(
    "https://api.autoalg.com/v1/json",
    headers={"X-API-Key": "YOUR_KEY"},
    json={"data": '{"a":1,"b":2}', "action": "format"}
)
print(resp.json()["result"])

JavaScript (fetch)

const resp = await fetch("https://api.autoalg.com/v1/json", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "YOUR_KEY"
  },
  body: JSON.stringify({ data: '{"a":1}', action: "format" })
});
const { result } = await resp.json();
console.log(result);

⚠️ 错误码

状态码说明
200请求成功
400请求参数错误(如无效 JSON、无效正则表达式等)
401未认证或 API Key 无效
422请求体格式错误(缺少必填字段等)
500服务器内部错误