HandleHttpRequest 参数化访问路径
1 目的
实现参数化访问路径,同时可以很方便地传入参数.
2 示例说明
输入数据:HTTP请求(仅测试URI,故body内容为空即可)
http://localhost:20001/api/zhangsan/p00048639/(+86)13504738493
输出数据:HTTP回复
you are zhangsan with id p00048639 and phonenumber is (+86)13504738493
3 流程说明
3.1 HandleHttpRequest 参数化路径配置
- 监听端口配置 : 设置未被占用端口即可,这里使用的是20001端口.
- 主机和会话服务无特殊配置略
- 允许路径设置 :可以使用自定义的变量来提取URI中对应的参数到对应的流属性中供下文使用,语法格式为{变量名}.
示例:/api/{name}/{id}/{phonenumber}
当使用URL "http://localhost:20001/api/zhangsan/p00048639/(+86)13504738493"发送请求 时,"zhangsan","p00048639","(+86)13504738493"会作为属性写入到输出数据流的属性中,且自动创建的属性键:
http.path.param.name
http.path.param.id
http.path.param.phonenumber
3.2 ReplaceText 调用流文件属性配置
替换值设置 :
you are ${http.path.param.name} with id ${http.path.param.id} and phonenumber is ${http.path.param.phonenumber}
4 实际输出数据
这里使用浏览器访问进行测试:
模板
参见附件(请右键另存保存):HTTP_参数化路径模板
场景
允许使用动态的URI来灵活地调用API.
Request URL中传入的参数自动保存在数据流属性中,编排时可以很方便地调用,省去了evaluate JSON的过程.