我已使用RAML文件通过APIKit路由器生成流。我有example.json作为示例响应。 我的RAML代码是:
#%RAML 0.8
---
title: TestEmployee API
version: v1
/employee:
get:
queryParameters:
id:
enum: [1,2,3,4]
required: true
type: string
description: Employee id
name:
enum: [Charles,John,Neha,Shruti]
required: true
type: string
description: Employee_name
responses:
200:
body:
application/json:
example: !include example.json
JSON示例响应为:
[
{
"id": 1,
"name":"Charles",
"code": "C1ENU00",
"dateofjoining":"2019/06/24",
"domain":"ENU",
"address":"Hyderabad",
"phone": 9865458936,
"program": "WASE"
},
{
"id": 2,
"name":"John",
"code": "C2DIG00",
"dateofjoining":"2019/06/24",
"domain":"DIGITAL",
"address":"Chennai",
"phone": 9756359864,
"program": "ELITE"
}
当“ id”和“ name”匹配时,我想使用选择路由器适当地调用流。就像在查询参数中一样,如果用户输入“ id = 1&name = Charles”,则只有选择路由器会调用主流程,否则它将调用默认流程。最初,有效负载设置为“示例JSON响应”正文。请指导我实现这一目标。
答案 0 :(得分:2)
在选择路由器中将when
expression
属性设置为与您的用例匹配的Dataweave表达式。您可以使用attribute.queryParams.YOUR-QUERY-PARAM-NAME语法按名称访问queryParams:
#[attributes.queryParams.id=='1' and attributes.queryParams.name=='Charles']
然后为您需要的每个路由添加一个when范围,为默认路由添加一个可选的否则:
<choice>
<when
expression="#[attributes.queryParams.id=='1' and attributes.queryParams.name=='Charles']">
<flow-ref name="some-flow" />
</when>
<otherwise>
<flow-ref name="some-other-flow" />
</otherwise>
</choice>
对于M子3,请使用:
#[message.inboundProperties.'http.query.params'.id == '1' && message.inboundProperties.'http.query.params'.name =='Charles']