Using the Request Method Transform with Tyk Classic APIs
Last updated: 3 minutes read.
Tyk’s request method transform middleware is configured at the endpoint level, where it modifies the HTTP method used in the request to a configured value.
When working with Tyk Classic APIs the transformation is configured in the Tyk Classic API Definition. You can do this via the Tyk Dashboard API or in the API Designer.
If you’re using the newer Tyk OAS APIs, then check out the Tyk OAS page.
If you’re using Tyk Operator then check out the configuring a Request Method Transform in Tyk Operator section below.
Configuring a Request Method Transform in the Tyk Classic API Definition
To configure a transformation of the request method you must add a new method_transforms
object to the extended_paths
section of your API definition.
It has the following configuration:
path
: the endpoint pathmethod
: the endpoint HTTP methodto_method
: The new HTTP method to which the request should be transformed
All standard HTTP methods are supported: GET
, PUT
, POST
, PATCH
, DELETE
, HEAD
, OPTIONS
.
For example:
{
"method_transforms": [
{
"path": "/status/200",
"method": "GET",
"to_method": "POST"
}
]
}
In this example the Request Method Transform middleware has been configured for HTTP GET
requests to the /status/200
endpoint. Any request received to that endpoint will be modified to POST /status/200
.
Configuring a Request Method Transform in the API Designer
You can use the API Designer in the Tyk Dashboard to configure the request method transform middleware for your Tyk Classic API by following these steps.
Using the Dashboard
Step 1: Add an endpoint for the path and select the Method Transform plugin
From the Endpoint Designer add an endpoint that matches the path for which you want to perform the transformation. Select the Method Transform plugin.
Step 2: Configure the transform
Then select the HTTP method to which you wish to transform the request.
Step 3: Save the API
Use the save or create buttons to save the changes and activate the middleware.
Configuring a Request Method Transform in Tyk Operator
The process for configuring a request method transform for an endpoint in Tyk Operator is similar to that defined in section configuring a Request Method Transform in the Tyk Classic API Definition.
To configure a transformation of the request method you must add a new method_transforms
object to the extended_paths
section of your API definition:
|
|
The example API Definition above configures an API to listen on path /transform
and forwards requests upstream to http://httpbin.org.
In this example the Request Method Transform middleware has been configured for HTTP GET
requests to the /anything
endpoint. Any request received to that endpoint will be modified to POST /anything
.