description |
---|
This page provides the technical details of the Override HTTP Method policy |
{% hint style="warning" %} This feature requires Gravitee's Enterprise Edition {% endhint %}
You can use the override-http-method
policy to override the HTTP method provided by the initial consumer with a new configured value when the inbound request is sent to the backend API.
This policy does not act on messages and only applies to the request phase of API flows.
Functional and implementation information for the override-http-method
policy is organized into the following sections:
{% hint style="warning" %} This policy can be applied to v2 APIs and v4 HTTP proxy APIs. It cannot be applied to v4 message APIs or v4 TCP proxy APIs. {% endhint %}
{% tabs %}
{% tab title="HTTP proxy API example" %}
The Gravitee echo API returns a JSON response when a GET
request is sent to https://api.gravitee.io/echo. The response is formatted as follows:
{% code title="Default response" %}
{
"bodySize": 0,
"headers": {
"Accept": "*/*",
"Host": "api.gravitee.io",
"User-Agent": "{{user-agent-info}}",
"X-Gravitee-Request-Id": "{{generated-request-id}}",
"X-Gravitee-Transaction-Id": "{{generated-trx-id}}",
"accept-encoding": "deflate, gzip"
},
"query_params": {}
}
{% endcode %}
This API would typically be called with just a GET
request, but if a client tries to run a PUT
request, they will get a 405 Method Not Allowed response. If the API publisher wants to ensure consistent behavior regardless of HTTP method called (in this case, returning the standard response), then adding an override-http-method
policy to convert the request from any method (e.g. PUT
, POST
, etc) to a GET
request will ensure that the expected response above is always returned.
{% endtab %}
{% endtabs %}
Sample policy configuration:
{% code title="Sample Configuration" %}
{
"name": "Custom name",
"description": "Overrides HTTP method",
"policy": "policy-override-request-method",
"configuration": {
"method": "GET"
}
{% endcode %}
The phases checked below are supported by the override-http-method
policy:
v2 Phases | Compatible? | v4 Phases | Compatible? |
---|---|---|---|
onRequest | true | onRequest | true |
onResponse | false | onResponse | false |
onRequestContent | false | onMessageRequest | false |
onResponseContent | false | onMessageResponse | false |
The override-http-method
policy can be configured with the following options:
Property | Required | Description | Type | Options |
---|---|---|---|---|
method | true | HTTP method used regardless of method called | GET POST PUT DELETE PATCH HEAD CONNECT OPTIONS TRACE |
The following is the compatibility matrix for APIM and theoverride-http-method
policy:
Plugin Version | Supported APIM versions |
---|---|
2.0 to 2.1 | 4.0+ |
Up to 1.x | Up to 3.20 |
There are no out-of-the-box errors returned by this policy.
{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-override-http-method/blob/master/CHANGELOG.md" %}