This topic discusses some of the API proxy development patterns demonstrated in the Apigee Edge cookbook samples. As we add more cookbook samples, we plan to add more patterns to this topic.
The policy composition pattern
Policy composition is an Apigee API proxy pattern that lets you combine results from multiple backend targets into a single response using policies. In effect, policy composition lets you create mashups using policies.
At the heart of the policy composition pattern is the ServiceCallout policy. The ServiceCallout policy acts as an HTTP client to the backend API or service. To be completely functional, however, a ServiceCallout relies on other policies to enable meaningful interaction with a remote API or service. Other policies are used to generate the request message that is sent by the ServiceCallout and to parse the content in the response message from the remote API or service.
The policy composition cookbook example uses three policies: AssignMessage, ServiceCallout, and ExtractVariables. These policies encapsulate the request message(s) you wish to send to the backend, the client that routes the message to the backend, and a message parser that parses the response from each API and assigns variables for the response data. After all the calls have been made, the collected variables are combined and returned in a single JSON object.
Here's a quick summary of these three policies:
- AssignMessage: Creates a request message, populates HTTP headers and query parameters, sets the HTTP verb.
- ServiceCallout: References a message created by the AssignMessage policy, defines a target URL for the external call, and defines a name for the response object that the target service returns.
- ExtractVariables: Typically defines a JSONPath or XPath expression that parses the message generated by the preceding ServiceCallout policy. The policy then sets variables containing the values parsed from the ServiceCallout response.
See Using policy composition for a complete example demonstrating the policy composition pattern.