Skip to content

Latest commit

 

History

History
96 lines (68 loc) · 4.28 KB

override-http-method.md

File metadata and controls

96 lines (68 loc) · 4.28 KB
description
This page provides the technical details of the Override HTTP Method policy

Override HTTP Method

{% hint style="warning" %} This feature requires Gravitee's Enterprise Edition {% endhint %}

Overview

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:

Examples

{% 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 %}

Configuration

Sample policy configuration:

{% code title="Sample Configuration" %}

{
  "name": "Custom name",
  "description": "Overrides HTTP method",
  "policy": "policy-override-request-method",
  "configuration": {
    "method": "GET"
  }

{% endcode %}

Phases

The phases checked below are supported by the override-http-method policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsefalseonResponsefalse
onRequestContentfalseonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Options

The override-http-method policy can be configured with the following options:

PropertyRequiredDescriptionTypeOptions
methodtrueHTTP method used regardless of method calledGET
POST
PUT
DELETE
PATCH
HEAD
CONNECT
OPTIONS
TRACE

Compatibility matrix

The following is the compatibility matrix for APIM and theoverride-http-method policy:

Plugin VersionSupported APIM versions
2.0 to 2.14.0+
Up to 1.xUp to 3.20

Errors

There are no out-of-the-box errors returned by this policy.

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-override-http-method/blob/master/CHANGELOG.md" %}