paramMapping
is a native plugin of Apache ShenYu Gateway and is used to edit your request param.shenyu-admin
--> BasicConfig --> Plugin --> paramMapping
, set to enable.paramMapping
dependency in the pom.xml file of the gateway.<!-- apache shenyu param_mapping plugin start--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-plugin-param-mapping</artifactId> <version>${project.version}</version> </dependency> <!-- apache shenyu param_mapping plugin end-->
Selectors and rules, please refer to:Selector And Rule Config。
addParameterKeys
: add a new key-value
on bodyreplaceParameterKeys
: replace request body's key
,key
is the value to be replaced,value
is the value after replacementremoveParameterKeys
: remove a body key
param_mapping modify the request body is achieved through JSONPath
, $.
represents the root directory.
use the configuration,unopened the plugin,request body is:
{"id":3,"data":{"value":"18","age":"36"}}
open the plugin,the final request body is
{"name":"shenyu","userId":3,"data":{"age":"36"}}
add a new key-value name:shenyu
,replace the key id
to userId
, remove the key data.value
.