Using the Request Method Transform with Tyk OAS 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 OAS APIs the transformation is configured in the Tyk OAS API Definition. You can do this via the Tyk Dashboard API or in the API Designer.
If you’re using the legacy Tyk Classic APIs, then check out the Tyk Classic page.
Configuring the Request Method Transform in the Tyk OAS API Definition
The request method transform middleware (transformRequestMethod
) 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). 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: (.*)
.
You only need to enable the middleware (set enabled:true
) and then configure toMethod
as the new HTTP method to which the request should be transformed. The design of the Tyk OAS API Definition takes advantage of the operationId
defined in the OpenAPI Document that declares both the path and method for which the method should be transformed.
All standard HTTP methods are supported: GET
, PUT
, POST
, PATCH
, DELETE
, HEAD
, OPTIONS
.
For example:
|
|
In this example the Request Method Transform middleware has been configured for requests to the GET /status/200
endpoint. Any request received to that endpoint will be modified to POST /status/200
.
The configuration above is a complete and valid Tyk OAS API Definition that you can import into Tyk to try out the request method transform.
Configuring the Request Method Transform in the API Designer
Adding the transform to your API endpoints is easy when using the API Designer in the Tyk Dashboard, simply follow these steps:
Step 1: Add an endpoint
From the API Designer add an endpoint that matches the path and method to which you want to apply the middleware.
Step 2: Select the Method Transform middleware
Select ADD MIDDLEWARE and choose the Method Transform middleware from the Add Middleware screen.
Step 3: Configure the middleware
Select the new HTTP method to which requests to this endpoint should be transformed
Select ADD MIDDLEWARE to apply the change to the middleware configuration.
Step 4: Save the API
Select SAVE API to apply the changes to your API.