首页 > 解决方案 > 您如何将来自多个请求的响应组合为客户端的单个响应?

问题描述

我在这本书中读到:这本书Kong: The king of API Gateways说您可以编写和转换 API 请求和响应。它建议您可以将许多响应组合成一个响应,因此客户端只需进行一次调用,而不必进行多次调用以获得单个页面的数据。这对于简化客户端调用将大有裨益。

问题是这本书实际上并没有告诉你如何使用 kong

我尝试使用请求和响应转换器,但这些仅对单个请求或响应进行更改。

标签: 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....**/
}

推荐阅读