Skip to content

Latest commit

 

History

History
101 lines (68 loc) · 6.27 KB

File metadata and controls

101 lines (68 loc) · 6.27 KB
description
This page provides the technical details of the HTTP Callout policy

HTTP Callout

Overview

You can use the callout-http policy to invoke an HTTP(S) URL and place a subset or all of the content in one or more variables of the request execution context.

This can be useful if you need some data from an external service and want to inject it during request processing.

The result of the callout is placed in a variable called calloutResponse and is only available during policy execution. If no variable is configured, the result of the callout is no longer available.

Functional and implementation information for the callout-http policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to v2 APIs and v4 proxy APIs. It cannot be applied to v4 message APIs. {% endhint %}

{% tabs %} {% tab title="Proxy API example" %} Sample policy configuration:

"policy-http-callout": {
    "method": "GET",
    "url": "https://api.gravitee.io/echo",
    "headers": [ {
        "name": "X-Gravitee-Request-Id",
        "value": "{#request.id}"
    }],
    "variables": [{
        "name": "my-server",
        "value": "{#jsonPath(#calloutResponse.content, '$.headers.X-Forwarded-Server')}"
    }]
}

{% endtab %} {% endtabs %}

Configuration

Phases

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

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsetrueonResponsetrue
onRequestContenttrueonMessageRequestfalse
onResponseContenttrueonMessageResponsefalse

Options

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

PropertyRequiredDescriptionTypeDefault
methodtrueHTTP Method used to invoke URLHTTP methodGET
useSystemProxytrueUse the system proxy configured by your administratorbooleanfalse
urltrueURL invoked by the HTTP client (support EL)URL-
headerstrueList of HTTP headers used to invoke the URL (support EL)HTTP Headers-
bodytrueThe body content send when calling the URL (support EL)string-
fireAndForgettrueMake the http call without expecting any response. When activating this mode, context variables and exit on error are useless.booleanfalse
variablestrueThe variables to set in the execution context when retrieving content of HTTP call (support EL)List of variables-
exitOnErrortrueTerminate the request if the error condition is truebooleanfalse
errorConditiontrueThe condition which will be verified to end the request (support EL)string{#calloutResponse.status >= 400 and #calloutResponse.status ⇐ 599}
errorStatusCodetrueHTTP Status Code sent to the consumer if the condition is trueint500
errorContenttrueThe body response of the error if the condition is true (support EL)string

System Proxy

If the option useSystemProxy is checked, proxy information will be read from JVM_OPTS or from the gravitee.yml file if JVM_OPTS is not set. The system properties are as follows:

PropertyRequiredDescription
system.proxy.hosttrueProxy Hostname or IP
system.proxy.porttrueThe proxy port
system.proxy.typetrueThe type of proxy (HTTP, SOCK4, SOCK5)
system.proxy.usernamefalseUsername for proxy authentication if any
system.proxy.passwordfalsePassword for proxy authentication if any

HTTP client proxy options

# global configuration of the http client
system:
  proxy:
    type: HTTP
    host: localhost
    port: 3128
    username: user
    password: secret

Compatibility matrix

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

Plugin VersionSupported APIM versions
2.x+3.18+
1.15.x+3.15.x to 3.17.x
1.13.x to 1.14.x3.10.x to 3.14.x
Up to 1.12.xUp to 3.9.x

Errors

HTTP status codeError template key
500An error occurred while invoking URL

You can override the default response provided by the policy with the response templates feature. These templates must be defined at the API level with the APIM Console Proxy > Response Templates function.

The error keys sent by this policy are as follows:

KeyParameters
CALLOUT_EXIT_ON_ERROR-
CALLOUT_HTTP_ERROR-

Changelogs

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