Context Variables provide storage of temporary data inside a flow so as to be able to 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 the Assign Variables policy to define the context variables which can then be used inside a Build Message policy to populate the request payload sent to the target service or as a response to the client.
Context variables are also populated by policies like Lookup Cache or within custom policies such as Java Call Out.
The context variables that are handled by the API gateway server are described below.
Context Variable | Variable Reference | Description |
---|---|---|
API Product/Developer variables | ||
API PRODUCT NAME | api.product.name | The name of the product subscribed to by the client making a request. This variable will be populated only if the project is secured using the API keys or OAuth 2.0 access tokens. |
API CONSUMER KEY | api.consumer.key | The Key corresponding to the client making a request. This variable will be populated only if the project is secured using the API keys or OAuth 2.0 access tokens. |
API PRODUCT QUOTA ALLOWED | api.product.quota.allowed | The quota for the product subscribed to by the client making a request. This variable will be populated only if the project is secured using the 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 a request. This variable will be populated only if the project is secured using the API keys or OAuth 2.0 access tokens. |
Proxy Path variables | ||
PROXY RESOURCE PATH | proxy.resource.path | The path of the resource invoked. For example, if a resource base path is items/{itemId} and a request has path items/myItem/price, then this variable will have the value 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 the value items/myItem. |
PROXY RESOURCE FORWARD PATH | proxy.resource.forward.path | The path in a 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 the value /response.json which 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. | The 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. | The 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. | The 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. | The 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 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 such as HTTP and HTTPS. |
PROXY REQUEST PATH INFO | proxy.project.path.info | The path through 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. Example: 1.0, 1.1. |
PROXY REQUEST METHOD | proxy.request.method | The method that is invoked on a resource by a client such as GET, POST, PUT, and DELETE. |
PROXY REQUEST IN TIME | proxy.request.in.time | The time when the request is 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 is sent to the target server. |
TARGET REQUEST HEADER PROPERTY PREFIX | target.request.header. | Headers 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 for the client such as Accept, a variable target.request.header.Accept can be defined. |
TARGET REQUEST QUERY PROPERTY PREFIX | target.request.query. | Query Parameters sent as part of a 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 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 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 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. | The 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. | The 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 when errors are detected. |
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 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 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 when the response is sent back to the client in milliseconds. |
PROXY RESPONSE SIZE | proxy.response.size | The size of the 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 variable 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 where 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 a 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. |