kong - 您如何将来自多个请求的响应组合为客户端的单个响应?
问题描述
我在这本书中读到:这本书Kong: The king of API Gateways
说您可以编写和转换 API 请求和响应。它建议您可以将许多响应组合成一个响应,因此客户端只需进行一次调用,而不必进行多次调用以获得单个页面的数据。这对于简化客户端调用将大有裨益。
问题是这本书实际上并没有告诉你如何使用 kong
我尝试使用请求和响应转换器,但这些仅对单个请求或响应进行更改。
解决方案
It should be pretty easy
You can actually use Java Aggregation Pattern as below.Assuming you have below Response from 3 calls:
1. public class EmployeeResponse extends Response{..};
2. public class SocialSecurityNumberResponse extends Response{..};
3. public class EmployeeSalaryResponse extends Response{..} ;
Following composite Response can be constructed:
public class CompositeEmployeeResponse extends Response{
private EmployeeResponse employeeResponse;
private SocialSecurityNumberResponse socialSecurityNumberResponse;
private EmployeeSalaryResponse employeeSalaryResponse;
/*....getters/setters....**/
}
推荐阅读
- c# - 使用 DataTables 时 DataGridView 中的额外行(带有 CheckBox 列)
- javascript - Angular 6 Reactive Form - 如何设置条件值?
- java - 如何使用带有java代码的mongodb在数据库中形成具有先前记录的链
- reactjs - 如何将 Content-Type 更改为 application/json React
- angular - Angular 6 how to correctly utilize focusout but prevent it's execution when clicking itself
- polymer - 冲洗功能总是使聚合物测试(用于 dom-if)通过
- javascript - 如何使post 405方法在php上工作
- php - Prestashop 1.6 中的社交共享模块中未捕获的 ArgumentCountError
- jenkins - 没有 Jenkinsfiles 的 Jenkins “github 组织” - 可能吗?
- javascript - JS从JSON解析后如何分配var的原型?