POST request samples
In this way, you can request your dubbo rpc service by defined one api for every cluster.
name: pixiu
description: pixiu sample
resources:
- path: '/api/v1/test-dubbo/:application/:interface'
type: restful
description: common
methods:
- httpVerb: POST
enable: true
timeout: 1000ms
inboundRequest:
requestType: http
integrationRequest:
requestType: dubbo
mappingParams:
- name: requestBody.values
mapTo: opt.values
- name: requestBody.types
mapTo: opt.types
- name: uri.application
mapTo: opt.application
- name: uri.interface
mapTo: opt.interface
- name: queryStrings.method
mapTo: opt.method
- name: queryStrings.group
mapTo: opt.group
- name: queryStrings.version
mapTo: opt.version
# Notice: this is the really paramTypes to dubbo service, it takes precedence over paramTypes when it is finally called.
clusterName: "test_dubbo"
curl host:port/api/v1/test-dubbo/UserService/com.dubbogo.proxy.UserService?group=test&version=1.0.0&method=GetUserByName -X POST -d '{"types":["string"],"values":"tc"}' --header "Content-Type: application/json"
result
{
"age": 18,
"code": 1,
"iD": "0001",
"name": "tc",
"time": "2020-12-20T20:54:38.746+08:00"
}
curl host:port/api/v1/test-dubbo/UserService/com.dubbogo.proxy.UserService?group=test&version=1.0.0&method=GetUserByCode -X POST -d '{"types":["int"],"values":1}' --header "Content-Type: application/json"
result
{
"age": 18,
"code": 1,
"iD": "0001",
"name": "tc",
"time": "2020-12-20T20:54:38.746+08:00"
}
curl host:port/api/v1/test-dubbo/UserService/com.dubbogo.proxy.UserService?group=test&version=1.0.0&method=UpdateUserByName -X POST -d '{"types":["string","body"],"values":["tc",{"id":"0001","code":1,"name":"tc","age":15}]}' --header "Content-Type: application/json"
result
true
const (
optionKeyTypes = "types"
optionKeyGroup = "group"
optionKeyVersion = "version"
optionKeyInterface = "interface"
optionKeyApplication = "application"
optionKeyMethod = "method"
optionKeyValues = "values"
)
By configuring mapTo with option keywords(listed below), Pixiu will assemble generic params to invoke.
// GenericService uses for generic invoke for service call
type GenericService struct {
Invoke func(ctx context.Context, req []interface{}) (interface{}, error) `dubbo:"$invoke"`
referenceStr string
}
dubbo generic types
Use for dubbogo GenericService#Invoke
func arg 2rd param.
Use for dubbogo GenericService#Invoke
func arg 1rd param.
Dubbo group in ReferenceConfig#Group
.
Dubbo version in ReferenceConfig#Version
.
Dubbo interface in ReferenceConfig#InterfaceName
.
Now only use for part of cache key.
Use for dubbogo GenericService#Invoke
func arg 3rd param.
request body
{
"types": ["string"],
"values": "tc"
}
- name: requestBody.types
mapTo: opt.types
requestBody.types
means body content with types key.opt.types
means use types option.{
"types": [
"java.lang.String",
"object"
],
"values": [
"tc",
{
"id": "0001",
"code": 1,
"name": "tc",
"age": 99
}
]
}
Please pay attention to the special situation of configuration the degrees of freedom is not very high, if can’t meet the scene, please mention issue, thank you.