【问题标题】:How do you combine the response from multiple requests to a single response for a client?您如何将来自多个请求的响应组合为客户端的单个响应?
【发布时间】:2019-04-26 11:26:32
【问题描述】:

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

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

我尝试使用请求和响应转换器,但它们只会对单个请求或响应进行更改。

【问题讨论】:

  • 我也对这个问题的答案感兴趣。

标签: kong


【解决方案1】:

我也在寻找类似的解决方案。找不到任何使用 Kong 的工具。可能的一种选择是使用 Lua 编写自定义插件。我将按照here 中提到的那样尝试它

[编辑] 这也可能有用。 https://docs.konghq.com/hub/reedelk/reedelk-transformer/

【讨论】:

    【解决方案2】:
    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....**/
    }
    

    【讨论】:

    • 这不是一个很有帮助的答案。你能举出使用Kong的例子吗?
    猜你喜欢
    • 1970-01-01
    • 2011-01-22
    • 2010-10-23
    • 2014-02-07
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    相关资源
    最近更新 更多