Service callout to hit two backends

I currently have two simple microservices one that returns a true or false and one that returns a string.

I need to be able to connect to the first microservice that returns a status of true or false in the header. If it returns false, then apigee needs to return an error and stop the execution. If it returns true, then it needs to send that response to the second microservice and allow the user to hit the second microservice.

I've looked online at the best solution for this and i've seen the ServiceCallout Policy is the best way of doing this task. But im not sure how i would implement this using this policy.

Any ideas would be much appreciated.

0 5 197
5 REPLIES 5

Hi Cory

I can think of two approaches to this.

Setting your first microservice as a proxy target endpoint, and having your second microservice invoked by a service callout in the proxy post flow (ie after the target endpoint).

Otherwise, you could use two different Service Callout Policies - one for each microservice.

https://docs.apigee.com/api-platform/reference/policies/service-callout-policy

I'd also recommend taking a look at this article that covers best practices on Error Handling patterns.

https://community.apigee.com/articles/23724/an-error-handling-pattern-for-apigee-proxies.html

Hi @dane knezic

Thanks for the quick response, would the first approach work if, in the future, multiple proxies need to hit the first microservice?

Hi Cory

Not sure I quite understand your question. It shouldnt matter how many proxies need to hit your first microservice. But it sounds like it might be a reusable scenario that might be better suited to a service callout in a shared flow that's reused across multiple proxies?

Hi @dane knezic,

yes i was wondering how i would add this in a shared flow so that it could be used across multiple proxies?

Hi Cory

In your shared flow, you could do your first service callout, and store a value in a variable based on the response