Want to merge two api services response together.

I have two api services which will get cart and item details(Json responses). Just want to merge the both the response when i call proxy api. Help me out here with steps.

0 1 4,088
1 REPLY 1

The standard way Apigee Edge works is as a smart proxy for HTTP requests.

An API Proxy in Apigee Edge

  • handles an inbound request,
  • may examine the contents of the request to perform authentication or authorization checks. (Check token or API key etc)
  • may modify the request
  • invokes a target with that possibly modified request
  • receives the response from the target
  • may examine or modify that response
  • sends the possibly modified response to the original client.

What you want to do is modify that "standard" flow; you want to invoke another endpoint and merge the two requests. This is a really common desire.

One way you can mash up (merge) several responses is to use the ServiceCallout, at some point in the API Proxy either in request processing or response processing, and then ... probably use a JavaScript step to "merge" the response from the target with the response from the ServiceCallout step. Here's a 4-minute screencast covering the topic.

A second way you can do what you want is to use a Hosted Target, and code the 2 requests in a nodejs program, which merges things the way you want. Here's a tutorial on Hosted Targets.

Either of those are good ways to solve your problem.