Context Variables

As of version 2.2 Tyk enables context variables to be injected into various middleware components. The context variables are formatted and accessed differently depending on the calling system.

Context variables are extracted from the request at the start of the middleware chain, and must be explicitly enabled in order fo them to be made available to your transforms.

They can be a useful way to move data within a request, for example, converting a FORM encoded POST into a JSON request, or to capture an IP address as a header.

To enable context variables, in your API Definitions set enable_context_vars to true.

The context variables that are available are:

  • request_data: If the inbound request contained any query data or form data, it will be available in this object, please see the transforms documentation for implementation
  • path_parts: The compoenents of the path, split on /, please see the transforms documentation for implementation
  • token: The inbound raw token (if bearer tokens are being used) of this user
  • path: The path that is being requested
  • remote_addr: The IP address of the connecting client

Components that use context variables:

  • The URL Rewriter
  • Header injection
  • Body transforms
Was this article helpful to you? Yes No