本地模式
说明
- 主要介绍在单机环境下,然后使用本地
API更新网关数据。配置属性:
shenyu:
local:
enabled: true
sha512Key: 123456
- 统一返回结果:
success
-
统一请求前缀:
localhost:9095/shenyu -
统一请求头:
localKey: 123456
插件数据
新增或者更新插件
新增或者更新插件
请求方式
POST
请求路径
/plugin/saveOrUpdate
请求参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| PluginData | PluginData | True | 插件对象(Body里面传Json对象) |
PluginData
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| id | String | False | 插件ID | |
| name | String | True | 插件名称 | |
| config | String | False | 插件配置(Json格式) | |
| role | String | False | 插件角色 | |
| enabled | Boolean | False | 是否开启 |
请求示例
POST body
{"id":3,"name":"divide","enabled":"true"}
清空所有数据
清空所有插件,选择器,规则数据
请求方式
GET
请求路径
/cleanAll
清空插件数据
清空单个插件,选择器,规则数据
请求方式
GET
请求路径
/cleanPlugin?name = xxxx
Request参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| name | String | true | 插件名称 |
删除插件
删除单个插件(不包含,插件里面的选择器与规则)
请求方式
GET
请求路径
/plugin/delete?name = xxxx
Request参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| name | String | true | 插件名称 |
删除所有插件
删除所有插件(不包含,插件里面的选择器与规则)
请求方式
GET
请求路径
/plugin/deleteAll
获取插件
根据名称获取插件数据
请求方式
GET
请求路径
/plugin/findByName?name=xxxx
Request参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| name | String | true | 插件名称 |
新增或更新选择器
新增或者更新插件
请求方式
POST
请求路径
/plugin/selector/saveOrUpdate
请求参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| SelectorData | SelectorData | True | 选择器对象(Body里面传Json对象) |
SelectorData
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| id | String | False | 选择器ID | |
| pluginName | String | True | 插件名称 | |
| name | String | False | 选择器名称(不填则默认生成 plugin:selector+随机数字) | |
| matchMode | Integer | False | 匹配模式(0:and;1:or),不填默认生成 And模式 | |
| type | Integer | False | 流量类型0:全流量;1:自定义流量)不填默认生成全流量 | |
| sort | Integer | False | 排序 ,不填默认生成 10 | |
| enabled | Boolean | False | 是否开启,不填默认生成 true | |
| logged | Boolean | False | 是否打印日志,不填默认生成为false | |
| handle | String | False | 选择器处理(Json对象,根据每个插件不同,传的对象不同) | |
| conditionList | Condition | False | 条件集合,自定义流量需要传,全流量不用传(Json List对象) |
Condition
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| paramType | String | True | 参数类型(post,uri,query,host,header,cookie,req_method,domain) | |
| operator | String | True | 匹配方式(match,=,regex,>,<,contains,SpEL,Groovy,TimeBefore,TimeAfter) | |
| paramName | String | False | 参数名称(uri 参数类型时候,可以不传) | |
| paramValue | Integer | False | 匹配值 |
请求示例
POST body
{
"pluginName": "divide",
"type": 1,
"handle": "[{\"upstreamUrl\":\"127.0.0.1:8089\"}]",
"conditionDataList": [{
"paramType": "uri",
"operator": "match",
"paramName": null,
"paramValue": "/**"
}]
}
返回数据
选择器ID
xxxxx
新增选择器与规则
新增一条选择器与多条规则
请求方式
POST
请求路径
/plugin/selectorAndRules
请求参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| SelectorRulesData | SelectorRulesData | True | 选择器规则对象(Body里面传Json对象) |
SelectorRulesData
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| pluginName | String | True | 插件名称 | |
| selectorName | String | False | 选择器名称(不填则默认生成 plugin:selector+随机数 字) | |
| matchMode | Integer | False | 匹配模式(0:and;1:or),不填默认生成 And模式 | |
| selectorHandler | String | False | 选择器处理(Json对象,根据每个插件不同,传的对象不同) | |
| conditionList | ConditionData | True | 选择器条件集合(Json List对象) | |
| ruleDataList | RuleLocalData | True | 规则对象集合(Json List对象) |
RuleLocalData
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| ruleName | String | False | 规则名称 | |
| ruleHandler | String | True | 规则处理(不同的插件传不同的值) | |
| matchMode | Integer | False | 匹配模式(0:and;1:or) | |
| conditionList | ConditionData | True | 规则条件集合(Json List对象) |
ConditionData
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| paramType | String | True | 参数类型(post,uri,query,host,header,cookie,req_method,domain) | |
| operator | String | True | 匹配方式(match,=,regex,>,<,contains,SpEL,Groovy,TimeBefore,TimeAfter) | |
| paramName | String | False | 参数名称(uri 参数类型时候,可以不传) | |
| paramValue | Integer | False | 匹配值 |
请求示例
POST body
{
"pluginName": "divide",
"selectorHandler": "[{\"upstreamUrl\":\"127.0.0.1:8089\"}]",
"conditionDataList": [{
"paramType": "uri",
"operator": "match",
"paramValue": "/http/**"
}],
"ruleDataList": [{
"ruleHandler": "{\"loadBalance\":\"random\"}",
"conditionDataList": [{
"paramType": "uri",
"operator": "=",
"paramValue": "/http/test/payment"
}]
}, {
"ruleHandler": "{\"loadBalance\":\"random\"}",
"conditionDataList": [{
"paramType": "uri",
"operator": "=",
"paramValue": "/http/order/save"
}]
}]
}
删除选择器
根据选择器id与插件名称删除选择器
请求方式
GET
请求路径
/plugin/selector/delete?pluginName=xxxx&&id=xxxx
Request参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| pluginName | String | true | 插件名称 | |
| id | String | true | 选择器id |
获取插件下的所有选择器
根据插件名称获取所有选择器
请求方式
GET
请求路径
/plugin/selector/findList?pluginName=xxxx
Request参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| pluginName | String | true | 插件名称 |
新增或更新规则
新增或者更新规则数据
请求方式
POST
请求路径
/plugin/rule/saveOrUpdate
请求参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| RuleData | RuleData | True | 规则对象(Body里面传Json对象) |
RuleData
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| id | String | False | 规则ID | |
| pluginName | String | True | 插件名称 | |
| name | String | False | 规则名称(不填则默认生成 plugin:rule+随机数字) | |
| selectorId | String | True | 选择器ID(不填则默认生成 plugin:rule+随机数字) | |
| matchMode | Integer | False | 匹配模式(0:and;1:or),不填默认生成 And模式 | |
| sort | Integer | False | 排序 ,不填默认生成 10 | |
| enabled | Boolean | False | 是否开启,不填默认生成 true | |
| logged | Boolean | False | 是否打印日志,不填默认生成为false | |
| handle | String | False | 规则处理(Json对象,根据每个插件不同,传的对象不同) | |
| conditionList | ConditionData | False | 条件集合(Json List对象) |
conditionList
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| paramType | String | True | 参数类型(post,uri,query,host,header,cookie,req_method,domain) | |
| operator | String | True | 匹配方式(match,=,regex,>,<,contains,SpEL,Groovy,TimeBefore,TimeAfter) | |
| paramName | String | False | 参数名称(uri 参数类型时候,可以不传) | |
| paramValue | Integer | False | 匹配值 |
请求示例
POST body
{
"pluginName": "divide",
"selectorId": 123456,
"handle": "{\"loadBalance\":\"random\"}",
"conditionDataList": [{
"paramType": "uri",
"operator": "=",
"paramValue": "/test"
}]
}
返回数据
规则ID
xxxxx
删除规则
根据选择器id与规则id删除规则
请求方式
GET
请求路径
/plugin/rule/delete?selectorId=xxxx&&id=xxxx
Request参数
| 名称 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| selectorId | String | true | 选择器ID | |
| id | String | true | 规则ID |