Files
aiaa-notification-server/docs/httpie/curls.md
T
ryan c74bab3033 fix(数据存储): 确保列表查询返回空数组而非 null,并补充 HTTPie/Postman API 文档
Motivation:
当数据库查询无结果时,Go 的 `var slice []Type` 声明会使 JSON 序列化输出 `null`,而非 `[]`。这在 API 响应中造成不一致,也增加了客户端的空值处理负担。改为 `make([]Type, 0)` 后空结果统一输出为 `[]`,提升 API 规范性。

Changes:

* 统一 store 层所有 List 方法使用 `make([]Type, 0)` 初始化切片,覆盖 Sources、Channels、Templates、Rules、MessageLogs 及 RuleChannels 查询
* 新增完整的 cURL 示例文档,覆盖全部 API 端点(通知、Source、Template、Channel、Rule、消息记录)
* 新增 Postman Collection JSON 文件,可直接导入 HTTPie 使用,包含环境变量配置
2026-07-31 22:09:39 +08:00

397 lines
7.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# HTTPie 可导入 cURL 集合
**推荐:** 直接导入 Postman 集合(一次导入全部)
```
docs/httpie/postman_collection.json
```
HTTPie → Import → Postman → 选择该文件。
**单条导入:** Import → cURL → 粘贴下方某一条完整 `curl`
替换占位符:
| 占位符 | 说明 |
|--------|------|
| `http://localhost:8080` | 服务地址 |
| `admin-sk-change-me` | `config.yaml``server.admin_key` |
| `SOURCE_API_KEY` | 创建 Source 返回的 `api_key` |
| `:id` / `1` | 资源数字 ID |
---
## Health
### 健康检查
```bash
curl -X GET 'http://localhost:8080/health'
```
---
## Notify
### 发送通知(JSON
```bash
curl -X POST 'http://localhost:8080/api/v1/notify' \
-H 'Authorization: Bearer SOURCE_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"event": "trade.open",
"data": {
"symbol": "BTC",
"price": 65000
}
}'
```
### 发送通知(Regex
```bash
curl -X POST 'http://localhost:8080/api/v1/notify' \
-H 'Authorization: Bearer SOURCE_API_KEY' \
-H 'Content-Type: text/plain' \
--data-binary 'trade.open BTC 开仓 价格:65000'
```
### 发送通知(Textevent=default
```bash
curl -X POST 'http://localhost:8080/api/v1/notify' \
-H 'Authorization: Bearer SOURCE_API_KEY' \
-H 'Content-Type: text/plain' \
--data-binary 'BTC 突破 68000,请注意风险'
```
---
## Sources
### 创建 SourceJSON
```bash
curl -X POST 'http://localhost:8080/api/v1/sources' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "trading-system",
"parse_mode": "json",
"status": 1
}'
```
### 创建 SourceRegex
```bash
curl -X POST 'http://localhost:8080/api/v1/sources' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "legacy-monitor",
"parse_mode": "regex",
"parse_pattern": "(?P<event>\\w+)\\s+(?P<message>.+)"
}'
```
### 创建 SourceText
```bash
curl -X POST 'http://localhost:8080/api/v1/sources' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "alert-bot",
"parse_mode": "text"
}'
```
### 列出 Source
```bash
curl -X GET 'http://localhost:8080/api/v1/sources' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 获取 Source
```bash
curl -X GET 'http://localhost:8080/api/v1/sources/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 更新 Source
```bash
curl -X PUT 'http://localhost:8080/api/v1/sources/1' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "trading-system",
"parse_mode": "json",
"status": 1
}'
```
### 删除 Source
```bash
curl -X DELETE 'http://localhost:8080/api/v1/sources/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
---
## Templates
### 创建 Template
```bash
curl -X POST 'http://localhost:8080/api/v1/templates' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "trade_open",
"content": "### {{.symbol}} 开仓\n价格: {{.price}}"
}'
```
### 列出 Template
```bash
curl -X GET 'http://localhost:8080/api/v1/templates' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 获取 Template
```bash
curl -X GET 'http://localhost:8080/api/v1/templates/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 更新 Template
```bash
curl -X PUT 'http://localhost:8080/api/v1/templates/1' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "trade_open",
"content": "### {{.symbol}} 开仓\n价格: {{.price}}"
}'
```
### 删除 Template
```bash
curl -X DELETE 'http://localhost:8080/api/v1/templates/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
---
## Channels
### 创建 ChannelEmail
```bash
curl -X POST 'http://localhost:8080/api/v1/channels' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "email-ops",
"type": "email",
"config": {
"to": ["148516886@qq.com"]
},
"status": 1
}'
```
### 创建 Channel(钉钉)
```bash
curl -X POST 'http://localhost:8080/api/v1/channels' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "dingtalk-prod",
"type": "dingtalk",
"config": {
"webhook_url": "https://oapi.dingtalk.com/robot/send?access_token=xxx",
"secret": "SEC..."
},
"status": 1
}'
```
### 创建 Channel(企业微信)
```bash
curl -X POST 'http://localhost:8080/api/v1/channels' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "wecom-ops",
"type": "wecom",
"config": {
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx"
},
"status": 1
}'
```
### 创建 ChannelBark
```bash
curl -X POST 'http://localhost:8080/api/v1/channels' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "bark-phone",
"type": "bark",
"config": {
"url": "https://api.day.app/<device_key>"
},
"status": 1
}'
```
### 列出 Channel
```bash
curl -X GET 'http://localhost:8080/api/v1/channels' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 获取 Channel
```bash
curl -X GET 'http://localhost:8080/api/v1/channels/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 更新 Channel
```bash
curl -X PUT 'http://localhost:8080/api/v1/channels/1' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "email-ops",
"type": "email",
"config": {
"to": ["148516886@qq.com"]
},
"status": 1
}'
```
### 删除 Channel
```bash
curl -X DELETE 'http://localhost:8080/api/v1/channels/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
---
## Rules
### 创建 Rule
```bash
curl -X POST 'http://localhost:8080/api/v1/rules' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"source_name": "trading-system",
"event": "trade.open",
"template_name": "trade_open",
"channels": ["email-ops"],
"conditions": [
{"field": "symbol", "op": "exists"},
{"field": "price", "op": "gt", "value": "0"}
],
"enabled": 1
}'
```
### 列出 Rule
```bash
curl -X GET 'http://localhost:8080/api/v1/rules' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 获取 Rule
```bash
curl -X GET 'http://localhost:8080/api/v1/rules/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 更新 Rule
```bash
curl -X PUT 'http://localhost:8080/api/v1/rules/1' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"source_name": "trading-system",
"event": "trade.open",
"template_name": "trade_open",
"channels": ["email-ops"],
"enabled": 1
}'
```
### 删除 Rule
```bash
curl -X DELETE 'http://localhost:8080/api/v1/rules/1' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 启用 Rule
```bash
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/enable' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 禁用 Rule
```bash
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/disable' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 启用规则下某渠道
```bash
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/channels/1/enable' \
-H 'Authorization: Bearer admin-sk-change-me'
```
### 禁用规则下某渠道
```bash
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/channels/1/disable' \
-H 'Authorization: Bearer admin-sk-change-me'
```
---
## Message Logs
### 查询消息记录
```bash
curl -X GET 'http://localhost:8080/api/v1/message-logs?source=trading-system&event=trade.open&status=success&page=1&page_size=20' \
-H 'Authorization: Bearer admin-sk-change-me'
```