Layer7 API Management

Expand all | Collapse all

Co-relation of Data from multiple sources

Jump to Best Answer
  • 1.  Co-relation of Data from multiple sources

    Posted 03-23-2020 05:39 AM
    Hi everyone,

    I have a requirement to co-relate and group data from different upstreams together based on an ID.

    I'm able to get the data, however am stumped onto how I can do data co-relation.

    Any thoughts/direction would be great!

    Thanks

    Regards,
    Shawn


  • 2.  RE: Co-relation of Data from multiple sources

    Posted 03-23-2020 12:59 PM
    Can you please provide more specific information about the use case? I am a little vague about what you are asking.

    ------------------------------
    Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
    ------------------------------



  • 3.  RE: Co-relation of Data from multiple sources

    Posted 03-23-2020 01:43 PM
    Hey Jay,

    Here is the case
    API 1 - UserAPI 1 - User[ { "id": 1, "name": "User 1" }, { "id": 2, "name": "User 2" }, { "id": 3, "name": "User 3" }]

    API 2 - Items[ { "id": "a", "userId": 1, "items": [....] }, { "id": "b", "userId": 1, "items": [....] }, { "id": "c", "userId": 1, "items": [....] }, { "id": "d", "userId": 2, "items": [....] }, { "id": "e", "userId": 2, "items": [....] }, { "id": "f", "userId": 2, "items": [....] }]

    The requirement will be to return a combined JSON i.e.

    [[ { "id": 1, "name": "User 1", "items": [ { "id": "a", "items": [] }, { "id": "b", "items": [] }, { "id": "c", "items": [] } ] }, { "id": 2, "name": "User 2", "items": [ { "id": "d", "items": [] }, { "id": "e", "items": [] }, { "id": "f", "items": [] } ] }, { "id": 3, "name": "User 3" }]

    Regards,
    Shawn



  • 4.  RE: Co-relation of Data from multiple sources
    Best Answer

    Posted 03-23-2020 05:50 PM
      |   view attached
    So you need to orchestrate two calls to backend APIs (what I consider downstream) into a single response to a request from a client. You will need to write policy that parses the two API responses and builds the response message. This will involve evaluating JSON Paths and looping through the results. I assume the samples you sent are meant to be JSON (they are not). Attached is policy that should help you understand what I mean. Import this into a test Web API service and hit it with a browser

    ------------------------------
    Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
    ------------------------------

    Attachment(s)

    xml
    Merge_JSON_Shawn_Ko.xml   22K 1 version