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 端点
认证
无需认证
响应示例
{"status": "ok", "timestamp": 1741664830}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| data | string | 必填 | JSON 字符串 |
| action | string | 可选 | format | minify | validate,默认 format |
| indent | int | 可选 | 缩进空格数 (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}"}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| data | string | 必填 | 要编码的文本或要解码的 Base64 字符串 |
| action | string | 可选 | 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=="}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| data | string | 必填 | 要编码/解码的字符串 |
| action | string | 可选 | 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"}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| data | string | 必填 | 要计算 Hash 的文本 |
| algorithms | string[] | 可选 | 算法列表,支持 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..."
}
}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| action | string | 必填 | now | to_date | to_timestamp |
| value | string | 条件 | 时间戳或日期字符串 (to_date/to_timestamp 时必填) |
| unit | string | 可选 | 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"
}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| token | string | 必填 | JWT token 字符串 |
响应
{
"header": {"alg": "HS256", "typ": "JWT"},
"payload": {"sub": "1234", "name": "test", "iat": 1516239022}
}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| count | int | 可选 | 生成数量 (1-100),默认 1 |
| uppercase | bool | 可选 | 大写输出,默认 false |
| no_hyphens | bool | 可选 | 去除连字符,默认 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-..."]}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| data | string | 必填 | YAML 或 JSON 字符串 |
| action | string | 可选 | 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}"}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| data | string | 必填 | SQL 语句 |
| action | string | 可选 | format | minify,默认 format |
| keyword_case | string | 可选 | upper | lower | capitalize,默认 upper |
| indent_width | int | 可选 | 缩进宽度 (0-8),默认 2 |
请求参数
| 参数 | 类型 | 必填 | 说明 |
| pattern | string | 必填 | 正则表达式 |
| text | string | 必填 | 待匹配文本 |
| flags | string | 可选 | 标志: i (忽略大小写) m (多行) s (dotall) |
响应
{
"pattern": "\\d+",
"match_count": 2,
"matches": [
{"match": "123", "start": 0, "end": 3, "groups": []},
{"match": "456", "start": 5, "end": 8, "groups": []}
]
}
请求参数
| 参数 | 类型 | 必填 | 说明 |
| text1 | string | 必填 | 原始文本 |
| text2 | string | 必填 | 修改后文本 |
响应
{
"diff": "--- original\n+++ modified\n...",
"lines_added": 2,
"lines_removed": 1
}
⚡ 快速上手
cURL
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 | 服务器内部错误 |