API / APIGEE Gateway Interview Questions
What are Apigee flow variables and how do you work with them?
Flow variables are runtime key-value pairs that carry contextual information through the Apigee request/response pipeline. They are the primary means by which policies share data with each other. Some variables are automatically populated by Apigee; others are created by policies like ExtractVariables or AssignMessage.
| Variable | Value | Set by |
|---|---|---|
| request.verb | HTTP verb (GET, POST, etc.) | Apigee (always) |
| request.path | Request URL path | Apigee (always) |
| proxy.pathsuffix | Path after the proxy base path | Apigee (always) |
| request.header.{name} | Named request header value | Apigee (always) |
| request.queryparam.{name} | Named query parameter value | Apigee (always) |
| response.status.code | HTTP status code from backend | Apigee (always) |
| target.url | The URL Apigee sends to backend | Apigee / can be overridden |
| client.ip | Client's IP address | Apigee (always) |
| system.timestamp | Current epoch timestamp (ms) | Apigee (always) |
| environment.name | Current environment name | Apigee (always) |
<!-- Reference a flow variable in policy XML using curly braces --> <AssignMessage name="AM.SetHeader"> <Set> <Headers> <!-- Reference built-in variable --> <Header name="x-request-path">{request.path}</Header> <!-- Reference variable set by ExtractVariables --> <Header name="x-order-id">{orderId}</Header> <!-- Reference verifyapikey variable --> <Header name="x-client-id">{verifyapikey.VerifyAPIKey.client_id}</Header> </Headers> </Set> </AssignMessage> <!-- Reference in a condition expression (no braces needed) --> <Flow name="OrdersFlow"> <Condition>request.verb == "GET" and proxy.pathsuffix MatchesPath "/orders/**"</Condition> </Flow> <!-- Set a variable using JavaScript --> // context.setVariable("myCustomVar", "hello"); // context.getVariable("request.header.x-api-key"); // var statusCode = context.getVariable("response.status.code");
More Related questions...