Context Variables provide a way to store temporary data inside a flow and then use it in the subsequent parts of the flow.
For example, a third party service can be called using the Service Call Out policy and the response is parsed using Assign Variables policy to define the context variables which can then be used inside a Build Message policy to populate the request payload to the target service or response to the client.
Context variables are also populated by policies like Lookup Cache or inside custom policies like Java Call Out.
The context variables that are handled by the API gateway server are as described in the list.
Context Variable | Variable Reference | Description |
---|---|---|
API Product/Developer variables | ||
API PRODUCT NAME | api.product.name | The name of the product to which the client making the request is subscribed to. This variable will be populated only if the project is secured using API keys or OAuth 2.0 access tokens. |
API CONSUMER KEY | api.consumer.key | The Key corresponding to the client making the request. This variable will be populated only if the project is secured using API keys or OAuth 2.0 access tokens. |
API PRODUCT QUOTA ALLOWED | api.product.quota.allowed | The quota for the product to which the client making the request is subscribed to. This variable will be populated only if the project is secured using API keys or OAuth 2.0 access tokens. It is used in Quota policy when Enforce Quota is applied while creating a project. |
API QUOTA WEIGHT | api.quota.weight | The weight of the request can be assigned using this Context Variable and then it can be used in Quota policy when Enforce Quota is applied while creating a project. |
API DEVELOPER ID | api.developer.id | The ID of the consumer making the request. This variable will be populated only if the project is secured using API keys or OAuth 2.0 access tokens. |
Proxy Path variables | ||
PROXY RESOURCE PATH | proxy.resource.path | The path of the resource which is invoked. For example, if a resource base path is items/{itemId} and a request has path items/myItem/price, then this variable will have value as items/myItem/price |
PROXY RESOURCE BASE PATH | proxy.resource.base.path | The base path of the resource. For example, if a resource base path is items/{itemId} and a request has path items/myItem/price, then this variable will have value as items/myItem |
PROXY RESOURCE FORWARD PATH | proxy.resource.forward.path | The path in the request after the resource base path. This path will be forwarded in the target request as well. For example, if a resource base path is items/{itemId} and a request has path items/myItem/response.json, then this variable will have value as /response.json and this will be appended to the path specified in the target for this resource. |
Proxy Request variables | ||
PROXY REQUEST SIZE | proxy.request.size | The size of the request received from the client. |
PROXY REQUEST HEADER PROPERTY PREFIX | proxy.request.header. | Any request header sent by the client can be retrieved inside a flow to define conditions or to evaluate them using this variable. |
PROXY REQUEST QUERY PROPERTY PREFIX | proxy.request.query. | Any request parameter sent by the client can be retrieved inside a flow to define conditions or to evaluate them using this variable. |
PROXY REQUEST FORM PROPERTY PREFIX | proxy.request.form. | Any form parameter sent by the client can be retrieved inside a flow to define conditions or to evaluate them using this variable. |
PROXY REQUEST PATH PROPERTY PREFIX | proxy.request.template. | Any template parameter sent by the client can be retrieved inside a flow to define conditions or to evaluate them using this variable. For example, for a resource with resource path as items/{itemId}, the itemId that has been sent in the request can be retrieved using the variable proxy.request.template.itemId |
PROXY REQUEST HTTP SCHEME | proxy.request.http.scheme | The scheme used by the client. Can be HTTP, HTTPS etc. |
PROXY REQUEST PATH INFO | proxy.project.path.info | The path at which the request has been received by the proxy. This includes the base path of the project. |
PROXY REQUEST HTTP VERSION | proxy.request.http.version | The HTTP version of the request received from the client, can be 1.0, 1.1 etc. |
PROXY REQUEST METHOD | proxy.request.method | The method that is invoked on the resource by the client such as GET, POST, PUT, and DELETE. |
PROXY REQUEST IN TIME | proxy.request.in.time | The time at which the request in received. This is the number of milliseconds, between the current time and midnight, January 1, 1970 UTC. |
Target Request variables | ||
TARGET REQUEST IN TIME | target.request.in.time | The time at which the request has been sent to the target server. |
TARGET REQUEST HEADER PROPERTY PREFIX | target.request.header. | Headers which have to be sent as part of the request to the target server can be populated using this prefix. The variables can be defined using the Assign Variable policy. For example, to define a header to the client such as Accept, a variable target.request.header.Accept can be defined. |
TARGET REQUEST QUERY PROPERTY PREFIX | target.request.query. | Query Parameters which have to be sent as part of the request to the target server can be populated using this prefix. The variables can be defined using the Assign Variable policy. For example, to define a Query Parameter to the client such as address, a variable target.request.query.address can be defined. |
TARGET REQUEST FORM PROPERTY PREFIX | target.request.form. | Form Parameters which have to be sent as part of the request to the target server can be populated using this prefix. The variables can be defined using the Assign Variable policy. For example, to define a Form Parameter to be sent to the target server from the client such as address, a variable target.request.form.address can be defined. |
TARGET REQUEST PATH | target.request.path | The path at which the request has to be sent to the target server can be modified based on the condition of the flow using this Context Variable. |
TARGET REQUEST METHOD | target.request.method | The path which needs to be invoked on the target server can be modified based on the condition of the flow using this Context Variable. |
TARGET REQUEST PROTOCOL VERSION | target.request.version | The HTTP version with which the request has to be sent to the target server can be modified based on the condition of the flow using this Context Variable. |
TARGET REQUEST PROTOCOL | target.request.protocol | The HTTP protocol with which the request has to be sent to the target server can be modified based on the condition of the flow using this Context Variable. |
Target Response variables | ||
TARGET RESPONSE HEADER PROPERTY PREFIX | target.response.header. | Any response header sent by the target server can be retrieved inside a flow to define conditions or to evaluate them using this variable. |
TARGET RESPONSE FORM PROPERTY PREFIX | target.response.form. | Any form parameter sent by the target server in its response can be retrieved inside a flow to define conditions or to evaluate them using this variable. |
TARGET RESPONSE REASON PHRASE | target.response.reason.phrase | The reason phrase received from the target server in case of errors. |
TARGET RESPONSE STATUS CODE | target.response.status.code | The status code received from the target server. |
TARGET RESPONSE OUT TIME | target.response.out.time | The time at which the response is received from the target server. |
Proxy Response variables | ||
PROXY RESPONSE FORM PROPERTY PREFIX | proxy.response.form. | Form Parameters which have to be sent as a response to the client can be populated using this prefix. The variables can be defined using the Assign Variable policy. |
PROXY RESPONSE HEADER PROPERTY PREFIX | proxy.response.header. | Headers which have to be sent as a response to the client can be populated using this prefix. The variables can be defined using the Assign Variables policy. For example, to define a response header to the client such as Content-Type, a variable proxy.response.header.Content-Type can be defined. |
PROXY RESPONSE OUT TIME | proxy.response.out.time | The time in milliseconds at which the response is sent back to the client. |
PROXY RESPONSE SIZE | proxy.response.size | The size of response sent back to the client. |
API Project variables | ||
API PROJECT ID | api.project.name | The name of the project. This variable is used for analytics. |
API PROJECT VERSION | api.project.version | The version of the project. |
API PROJECT CONTEXT PATH | api.project.context.path | The base path of the API project. This is used for analytics. |
Client Variables | ||
CLIENT IP | client.ip | The IP Address of the client making the request. |
CLIENT HOST NAME | client.hostname | The host name of the client making the request. |
CLIENT REQUEST PORT | client.port | The port at which the client is sending the request. |
Streaming variables | ||
REQUEST STREAMING ENABLED | request.streaming.enabled | The variable provides information if streaming is enabled while sending a request to the target server. |
RESPONSE STREAMING ENABLED | response.streaming.enabled | The variable provides information if streaming is enabled while sending response from the target server to the client. |
Cache variables | ||
RESPONSE CACHE NAME | response.cache.name | The cache into which the response is cached when Response Cache policy is being used. |
CACHE HIT | cache.hit | The variable which determines if the cache has been hit. |
Target Fail over variables | ||
TARGET FAILOVER OCCURRED | target.failover.occurred | The variable which identifies if a target fail over has occurred. |
TARGET FAILOVER FROM | target.failover.from | The ID of the target configuration from which the fail over occurred. |
TARGET FAILOVER TO | target.failover.to | The ID of the target configuration to which the fail over has occurred. |
Environment variables | ||
ENVIRONMENT NAME | environment.name | The name of the environment through which this request is passing. |