Forward Request depending on the response

Hi,

I'm new to Apigee. I have a use case where the API proxy needs to call a 2nd microservice depending on the response from the first microservice. please find the overview of the use case attached here.

 

Piyumi_0-1629395597149.png

 

The API proxy needs to call Microservice 1 at first and depending on the response from Microservice 1 it either needs to return the response to the client or call a different microservice (Microservice 2) and return the response from Microservice 2. 

I have included the request forwarding logic that I need to achieve for this use case in the diagram(API proxy) as well.

Is this kind of request forwarding mechanism achievable at the Apigee proxy level. If so can you suggest what are the policies that we can utilize to achieve this optimum manner?

 

Update-
The request  from the client will be a POST request and the same request body needs to be forwarded to Micro service 1 and Micro service 2 on verification.

1 7 274
7 REPLIES 7

APR
Bronze 1
Bronze 1

Hi Piyumi,

Its achievable through Apigee proxy. simplest solution would be connect to first micro service using HTTPTargetConnection and in the target response flow extract the response body variables  and populate the flow variable using JavaScript policy and use service callout to connect second micro(execute only if condition matches).

Thank you @APR for your response. The request  from the client will be a POST request and the same request body needs to be forwarded to Micro service 1 and Micro service 2. Does the suggested approach still works ?.

Yes.

Not quite sure what is the error code for such failures (response_1.body.errorcode scenario) or treated as success with 200 .. but you may endup having the logic implemented based of conditional flow in the error flow if it is non 200 error code.

Thank you @API-Evangelist . At the Micro service 1 level the response will be a non 200 with an specific error code (to  distinguish this forwarding requirement).

You can use "RouteRule", to determinate the next step: 

This can help you:

https://docs.apigee.com/api-platform/fundamentals/understanding-routes

Thank you the reply.. When we use the route rules can we perform the conditional forwarding depending on the response parameters ?. As per the examples given in the documentation we can use request parameters.

In addition to the great suggestions already given in this thread, I can add that you can try Conditional Flow logic inside Proxy or Target definition. 

thanks, 

regards,