API / APIGEE Gateway Interview Questions
What is the ExtractVariables policy and how does it work with flow variables?
The ExtractVariables policy extracts content from HTTP messages (headers, query parameters, URI path, JSON body, XML body, form parameters) and stores the values in named flow variables. These variables can then be referenced in conditions and other policies throughout the proxy.
<!-- Extract from JSON request body --> <ExtractVariables name="EV.ExtractBody"> <Source>request</Source> <JSONPayload> <Variable name="orderId"> <JSONPath>$.order.id</JSONPath> </Variable> <Variable name="customerId"> <JSONPath>$.order.customer.id</JSONPath> </Variable> </JSONPayload> </ExtractVariables> <!-- Extract from URI path pattern: /orders/{orderId}/items/{itemId} --> <ExtractVariables name="EV.PathVars"> <Source>request</Source> <URIPath> <Pattern ignoreCase="true">/orders/{orderId}/items/{itemId}</Pattern> </URIPath> </ExtractVariables> <!-- Extract from query parameter --> <ExtractVariables name="EV.QueryParam"> <Source>request</Source> <QueryParam name="customerId"> <Pattern>{customerId}</Pattern> </QueryParam> </ExtractVariables> <!-- Now use the variable in a condition or another policy --> <!-- Example: add the orderId as a backend header --> <AssignMessage name="AM.InjectOrderId"> <Set> <Headers> <Header name="x-order-id">{orderId}</Header> </Headers> </Set> </AssignMessage>
More Related questions...