您如何将多个请求的响应合并为客户端的单个响应?

时间:2019-04-26 11:26:32

标签: kong

我在这本名为Kong: The king of API Gateways的书中读到,说您可以编写和转换API请求和响应。它建议您可以将许多响应合并为一个响应,因此客户端只需要进行一次调用,而不必进行更多操作才能获得单个页面的数据。这将对简化客户呼叫非常有益。

问题在于这本书实际上并没有告诉您如何使用kong

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

1 个答案:

答案 0 :(得分:-1)

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