API / APIGEE Gateway Interview Questions
What is the ServiceCallout policy and when would you use it?
The ServiceCallout policy allows an Apigee proxy to make an additional HTTP call to an external service within the same request/response pipeline. The response from that external call is stored in a variable and can be used by subsequent policies, all before returning the final response to the client.
<!-- ServiceCallout: call an identity service to enrich the request --> <ServiceCallout name="SC.GetUserProfile"> <Request variable="userProfileRequest"> <Set> <Headers> <Header name="Authorization">Bearer {request.header.authorization}</Header> </Headers> </Set> </Request> <Response>userProfileResponse</Response> <HTTPTargetConnection> <URL>https://identity.internal.example.com/profile/{userId}</URL> </HTTPTargetConnection> </ServiceCallout> <!-- Then extract data from the callout response --> <ExtractVariables name="EV.ExtractProfile"> <Source>userProfileResponse</Source> <JSONPayload> <Variable name="userRole"> <JSONPath>$.role</JSONPath> </Variable> </JSONPayload> </ExtractVariables> <!-- Use the role in a condition to allow/deny access --> <!-- Condition: userRole = "admin" -->
| Use case | Description |
|---|---|
| Identity enrichment | Call an IdP to get user roles before authorisation decision |
| Data lookup | Fetch customer data from CRM to add to request |
| Token exchange | Exchange one token type for another with an external service |
| Webhook notification | Send event notification before/after backend call |
| Fraud check | Call a fraud detection service and block if flagged |
More Related questions...