x-request-id
it will be added to the request as X-Request-Id
.
In the request middleware chain, the API-level transform is applied before the endpoint-level transform so if both middleware are enabled, the endpoint-level transform will operate on the headers that have been added by the API-level transform (and will not receive those that have been deleted by it).
$tyk_context.
namespace$tyk_meta.
namespacetransformRequestHeaders
object to the middleware.global
section of the Tyk OAS Extension (x-tyk-api-gateway
) in your Tyk OAS API Definition.
You only need to enable the middleware (set enabled:true
) and then configure the details of headers to add
and those to remove
.
For example:
X-Static
with the value foobar
X-Request-ID
with a dynamic value taken from the request_id
context variablesX-User-ID
with a dynamic value taken from the uid
field in the session metadataAuth_Id
operationId
defined in the OpenAPI Document that declares both the path and method for which the middleware should be added. Endpoint paths
entries (and the associated operationId
) can contain wildcards in the form of any string bracketed by curly braces, for example /status/{code}
. These wildcards are so they are human readable and do not translate to variable names. Under the hood, a wildcard translates to the “match everything” regex of: (.*)
.
The request header transform middleware (transformRequestHeaders
) can be added to the operations
section of the Tyk OAS Extension (x-tyk-api-gateway
) in your Tyk OAS API Definition for the appropriate operationId
(as configured in the paths
section of your OpenAPI Document).
The transformRequestHeaders
object has the following configuration:
enabled
: enable the middleware for the endpointadd
: a list of headers, in key:value pairs, to be appended to the requestremove
: a list of headers to be deleted from the request (if present)GET /status/200
endpoint. Any request received to that endpoint will have the X-Static
header removed and the X-Secret
header added, with the value set to the-secret-key-is-secret
.
The configuration above is a complete and valid Tyk OAS API Definition that you can import into Tyk to try out the endpoint-level request header transform.
X-Static
header will be added (by the API-level transform) and then removed (by the endpoint-level transform) such that the overall effect of the two transforms for a call to GET /status/200
would be to add three headers:
X-Request-ID
X-User-ID
X-Secret
Auth_Id
global_headers
object to the versions
section of your API definition. This contains a list of key:value pairs, being the names and values of the headers to be added to requests.
To delete headers from all requests to your API, you must add a new global_headers_remove
object to the versions
section of the API definition. This contains a list of the names of existing headers to be removed from requests.
For example:
X-Static
with the value foobar
X-Request-ID
with a dynamic value taken from the request_id
context variablesX-User-ID
with a dynamic value taken from the uid
field in the session metadataAuth_Id
transform_headers
object to the extended_paths
section of your API definition.
It has the following configuration:
path
: the endpoint pathmethod
: the endpoint HTTP methoddelete_headers
: A list of the headers that should be deleted from the requestadd_headers
: A list of headers, in key:value pairs, that should be added to the requestpath
can contain wildcards in the form of any string bracketed by curly braces, for example {user_id}
. These wildcards are so they are human readable and do not translate to variable names. Under the hood, a wildcard translates to the “match everything” regex of: (.*)
.
For example:
GET
requests to the /status/200
endpoint. Any request received to that endpoint will have the X-Static
header removed and the X-Secret
header added, with the value set to the-secret-key-is-secret
.
X-Static
header will be added (by the API-level transform) and then removed (by the endpoint-level transform) such that the overall effect of the two transforms for a call to GET /status/200
would be to add three headers:
X-Request-ID
X-User-ID
X-Secret
Auth_Id
ApiDefinition
:
global_headers
: Mapping of key values corresponding to headers to add to API requests.global_headers_remove
: List containing the name of headers to remove from API requests.ApiDefinition
custom resource that adds foo-req and bar-req headers to the request before it is sent upstream. The foo-req header has a value of foo-val and the bar-req header has a value of bar-val. Furthermore, the hello header is removed from the request before it is sent upstream.
transform_headers
object to the extended_paths
section of your API definition.
In the example below the Request Header Transform middleware (transform_headers
) has been configured for HTTP POST
requests to the /anything
endpoint. Any request received to that endpoint will have the remove_this
header removed and the foo
header added, with the value set to bar
.