规则引擎 HTTP API
规则 API
创建规则
API 定义:
POST api/v3/rules
参数定义:
rawsql | String,用于筛选和转换原始数据的 SQL 语句 |
---|---|
actions | JSON Array,动作列表 actions.name String, 动作名字 actions.params JSON Object, 动作参数 |
description | String,可选,规则描述 |
API 请求示例:
GET http://localhost:8080/api/v3/rules
API 请求消息体:
{
"rawsql": "select * from \"message.publish\"",
"actions": [{
"name": "inspect",
"params": {
"a": 1
}
}],
"description": "test-rule"
}
API 返回数据示例:
{
"code": 0,
"data": {
"actions": [{
"name": "inspect",
"params": {
"a": 1
}
}],
"description": "test-rule",
"enabled": true,
"for": "message.publish",
"id": "rule:34476883",
"rawsql": "select * from \"message.publish\""
}
}
查询规则
API 定义:
GET api/v3/rules/:id
API 请求示例:
GET api/v3/rules/rule:34476883
API 返回数据示例:
{
"code": 0,
"data": {
"actions": [{
"name": "inspect",
"params": {
"a": 1
}
}],
"description": "test-rule",
"enabled": true,
"for": "message.publish",
"id": "rule:34476883",
"rawsql": "select * from \"message.publish\""
}
}
获取当前规则列表
API 定义:
GET api/v3/rules
API 返回数据示例:
{
"code": 0,
"data": [{
"actions": [{
"name": "inspect",
"params": {
"a": 1
}
}],
"description": "test-rule",
"enabled": true,
"for": "message.publish",
"id": "rule:34476883",
"rawsql": "select * from \"message.publish\""
}]
}
删除规则
API 定义:
DELETE api/v3/rules/:id
请求参数示例:
DELETE api/v3/rules/rule:34476883
API 返回数据示例:
{
"code": 0
}
动作 API
获取当前动作列表
API 定义:
GET api/v3/actions?for=${hook_type}
API 请求示例:
GET api/v3/actions
API 返回数据示例:
{
"code": 0,
"data": [{
"app": "emqx_rule_engine",
"description": "Republish a MQTT message to another topic",
"for": "message.publish",
"name": "republish",
"params": {
"target_topic": {
"description": "To which topic the message will be republished",
"format": "topic",
"required": true,
"title": "To Which Topic",
"type": "string"
}
},
"types": []
}]
}
API 请求示例:
GET 'api/v3/actions?for=client.connected'
API 返回数据示例:
{
"code": 0,
"data": [{
"app": "emqx_rule_engine",
"description": "Inspect the details of action params for debug purpose",
"for": "$any",
"name": "inspect",
"params": {},
"types": []
}]
}
查询动作
API 定义:
GET api/v3/actions/:action_name
API 请求示例:
GET 'api/v3/actions/inspect'
API 返回数据示例:
{
"code": 0,
"data": {
"app": "emqx_rule_engine",
"description": "Inspect the details of action params for debug purpose",
"for": "$any",
"name": "inspect",
"params": {},
"types": []
}
}
资源类型 API
获取当前资源类型列表
API 定义:
GET api/v3/resource_types
返回数据示例:
{
"code": 0,
"data": [{
"config": {
"url": "http://host-name/chats"
},
"description": "forward msgs to host-name/chats",
"id": "resource:a7a38187",
"type": "web_hook"
}]
}
查询资源类型
API 定义:
GET api/v3/resource_types/:type
返回数据示例:
GET api/v3/resource_types/web_hook
{
"code": 0,
"data": {
"description": "WebHook",
"name": "web_hook",
"params": {},
"provider": "emqx_web_hook"
}
}
获取某种类型的资源
API 定义:
GET api/v3/resource_types/:type/resources
API 请求示例:
GET api/v3/resource_types/web_hook/resources
API 返回数据示例:
{
"code": 0,
"data": [{
"config": {"url":"http://host-name/chats"},
"description": "forward msgs to host-name/chats",
"id": "resource:6612f20a",
"type": "web_hook"
}]
}
资源 API
创建资源
API 定义:
POST api/v3/resources
API 参数定义:
type | String, 资源类型 |
---|---|
config | JSON Object, 资源配置 |
description | String,可选,规则描述 |
API 请求参数示例:
{
"type": "web_hook",
"config": {
"url": "http://127.0.0.1:9910",
"headers": {"token":"axfw34y235wrq234t4ersgw4t"},
"method": "POST"
},
"description": "web hook resource-1"
}
API 返回数据示例:
{
"code": 0,
"data": {
"config": {
"headers":{"token":"axfw34y235wrq234t4ersgw4t"},
"method":"POST",
"url":"http://127.0.0.1:9910"
},
"description": "web hook resource-1",
"id": "resource:62763e19",
"type": "web_hook"
}
}
获取资源列表
API 定义:
GET api/v3/resources
API 返回数据示例:
{
"code": 0,
"data": [{
"config": {
"headers":{"token":"axfw34y235wrq234t4ersgw4t"},
"method":"POST",
"url":"http://127.0.0.1:9910"
},
"description": "web hook resource-1",
"id": "resource:62763e19",
"type": "web_hook"
}]
}
查询资源
API 定义:
GET api/v3/resources/:resource_id
API 返回数据示例:
GET 'api/v3/resources/resource:62763e19'
{
"code": 0,
"data": {
"config": {
"headers":{"token":"axfw34y235wrq234t4ersgw4t"},
"method":"POST",
"url":"http://127.0.0.1:9910"
},
"description": "web hook resource-1",
"id": "resource:62763e19",
"type": "web_hook"
}
}
删除资源
API 定义:
DELETE api/v3/resources/:resource_id
API 返回数据示例:
DELETE 'api/v3/resources/resource:62763e19'
{
"code": 0
}