-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
984 additions
and
320 deletions.
There are no files selected for viewing
49 changes: 25 additions & 24 deletions
49
...cs/content/advanced-configuration/transform-traffic/request-method-transform.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
--- | ||
date: 2017-03-23T17:45:01Z | ||
title: Request Method Transform | ||
menu: | ||
main: | ||
parent: "Transform Traffic" | ||
weight: 6 | ||
title: Request Method Transformation | ||
tags: ["Request Transform", "Method Transform", "transform"] | ||
description: "How to transform the HTTP Method for an API Request" | ||
--- | ||
|
||
It is now possible, as of Tyk Gateway v2.2, to change the method of a request. To enable, add to your extended paths: | ||
## Overview | ||
Tyk's Request Method Transform middleware allows you to modify the HTTP method of incoming requests to an API endpoint prior to the request being proxied to the upstream service. You might use this, for example, to map requests from older clients to the latest API version, ensuring backward compatibility and a smooth transition for clients that have not yet updated to the latest version. It is a simple middleware that changes only the method and not the payload or headers. You can, however, combine this with the [Request Header Transform]({{< ref "transform-traffic/request-headers" >}}) and [Request Body Tranform]({{< ref "transform-traffic/request-body" >}}) to apply more complex transformation to requests. | ||
|
||
```{.copyWrapper} | ||
method_transforms: [ | ||
{ | ||
path: "post", | ||
method: "GET", | ||
to_method: "POST" | ||
} | ||
], | ||
``` | ||
{{< note success >}} | ||
**Note** | ||
## When to use request method transformation | ||
#### Simplifying API consumption | ||
In cases where an upstream API requires different methods (e.g. `PUT` or `DELETE`) for different functionality but you want to wrap this in a single client-facing API, you can provide a simple interface offering a single method (e.g. `POST`) and then use the method transform middleware to map requests to correct upstream method. | ||
|
||
This feature is very simple at the moment, and only changes the type of method, it does not handle the message data of the request body. However, a combination of method transform, context variables and body transformations can be used to achieve a similar effect. | ||
{{< /note >}} | ||
#### Enforcing API governance and standardisation | ||
You can use the method transform to ensure that all requests to a service are made using the same method, regardless of the original method used by the client. This can help maintain consistency across different client applications accessing the same upstream API. | ||
|
||
#### Error Handling and Redirection | ||
You can use the method transformation middleware to handle errors and redirect requests to different endpoints, such as changing a DELETE request to a GET request when a specific resource is no longer available, allowing for graceful error handling and redirection. | ||
|
||
### Using the Dashboard | ||
#### Testing and debugging | ||
Request method transformation can be useful when testing or debugging API endpoints; temporarily changing the request method can help to identify issues or test specific functionalities. | ||
|
||
To do this from the Dashboard, from the **API Endpoint Designer** select **method transform** from the plugins drop-down list on the endpoint you want to transform from. | ||
## How the request method transform works | ||
This is a very simple middleware that is assigned to an endpoint and configured with the HTTP method to which the request should be modified. The Request Method Transform middleware modifies the request method for the entire request flow, not just for the specific upstream request, so all subsequent middleware in the processing chain will use the new (transformed) method. | ||
|
||
{{< img src="/img/2.10/method_transform.png" alt="Method Transform" >}} | ||
<hr> | ||
|
||
Then select the path you wish to change to. | ||
If you're using Tyk OAS APIs, then you can find details and examples of how to configure the request method transform middleware [here]({{< ref "product-stack/tyk-gateway/middleware/request-method-tyk-oas" >}}). | ||
|
||
{{< img src="/img/2.10/method_transform2.png" alt="Method Path" >}} | ||
If you're using Tyk Classic APIs, then you can find details and examples of how to configure the request method transform middleware [here]({{< ref "product-stack/tyk-gateway/middleware/request-method-tyk-classic" >}}). | ||
|
||
<!-- proposed "summary box" to be shown graphically on each middleware page | ||
## Request Method Transform middleware summary | ||
- The Request Method Transform is an optional stage in Tyk's API Request processing chain, sitting between the [TBC]() and [TBC]() middleware. | ||
- The Request Method Transform is configured at the per-endpoint level within the API Definition and is supported by the API Designer within the Tyk Dashboard. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.