DataPower Gateway (Classic)
only

Configuring the Invoke policy for DataPower Gateway (v5 compatible)

Follow these steps to configure the Invoke policy for DataPower® Gateway (v5 compatible) in the assembly user interface.

About this task

Note: This topic describes the Invoke policy implementation in the DataPower Gateway (v5 compatible). If you are using the DataPower API Gateway, see Configuring the Invoke policy for DataPower API Gateway. For information about the different types of gateway, see API Connect gateway types.

For details on how to configure the policy in your OpenAPI source, see invoke.

You might notice that the last invoke in their policy is replaced by a proxy. The replacement is sometimes done automatically by the IBM® API Connect DataPower Gateway to improve performance. The proxy is functionally equivalent to the invoke, but the API caller might notice the following differences when proxy is used.
  • If the HTTP request made by the invoke or proxy gets a redirect (3xx) response:
    • invoke returns the response from following the redirect response.
    • proxy does not follow 3xx responses, and the redirect response is returned.
  • The IBM API Connect test tool shows that proxy was used, but invoke appears in the analytics latency records.
  • The response from the proxy can contain different whitespace or escaping than a response from invoke. Despite the differences in the response, it is still valid.
If you want to prevent replacement of the last invoke in the assembly with proxy, you can set the API property api.properties.x-ibm-gateway-optimize-invoke to false. For more information, see API properties.

Procedure

  1. In the navigation pane, click Develop icon in the navigation pane Develop, then select the APIs tab.
    The Develop page opens.
  2. Click the title of the API definition that you want to work with.
  3. Select the Gateway tab, then click Policies in the navigation pane.
    For more information about working with the assembly editor for an API, see The assembly editor.
  4. Find the Invoke policy in the palette, and drag the policy onto your canvas.
  5. Specify the following properties.
    Table 1. Invoke policy properties
    Property label Required Description Data type
    Title Yes The title of the policy.

    The default value is invoke.

    string
    Description No A description of the policy. string
    URL Yes Specifies a URL for the target service.

    For a SOAP API, a URL is added by default. Where possible, the Invoke URL value is pre-supplied from information that is defined in the imported WSDL.

    string
    TLS profile No Specifies a TLS profile to use for the secure transmission of data. string
    Timeout Yes The time to wait before a reply from the endpoint (in seconds).

    The default value is 60.

    integer
    Follow redirects No Specifies the behavior if the back-end server returns the HTTP status code 301 Moved Permanently. If you select this checkbox, the invoke policy follows the URL redirection by making a further call to the URL specified in the Location header in the response. If you clear this checkbox, the invoke saves the 301 status code and the API call is considered to be complete.
    Note: The follow-redirect property is supported only by the DataPower API Gateway. If you are using the DataPower Gateway (v5 compatible), the invoke always follows the URL redirection; the proxy policy (not supported by the DataPower API Gateway) saves the 301 status code and completes the API call without following the URL redirection.
    boolean
    Username No The username to use for HTTP Basic authentication. string
    Password No The password to use for HTTP Basic authentication. string
    HTTP Method Yes The HTTP method to use for the Invoke. The following values are valid.
    • Keep
    • GET
    • POST
    • PUT
    • DELETE
    • PATCH
    • HEAD
    • OPTIONS
    The default value is GET. However, if set to Keep, or the property is removed from the source, the HTTP method from the incoming request is used.
    string
    Compression No Select this checkbox to enable Content-Encoding compression on upload.

    The checkbox is cleared by default.

    boolean

    Cache Type

    No The cache type determines whether to cache documents, honoring or overriding the HTTP Cache Control directives received in the response from the target URL. This property takes effect only when a response is received, otherwise the policy always returns the non-expired response that was previously saved in cache.
    Valid values are:
    Protocol
    The cache behavior is determined by the Cache-Control headers on the response, in accordance with RFC 7234.

    To optimize performance, if the gateway receives more than one request for a resource that is not in the cache but could be cached when the response from the target URL is received, the gateway sends only one request to the target URL; the remaining requests are not processed until the response from the first request has been received and the cache behavior has been determined from this response. If the response indicates that caching is possible, the gateway responds to all waiting requests with the cached resource. If the response indicates that caching is not possible, the gateway sends all waiting requests to the target URL.

    Use this option only if you expect that responses from the target URL can be cached, in which case it should improve performance and limit the demand on the target URL. If, however, the target URL never indicates that the gateway should cache its response, performance might be impaired when compared to the No Cache option.

    No Cache
    Responses from the target URL are not cached on the gateway regardless of any caching headers returned. In this case, every request from the client is sent to the target URL.

    Use this option if you do not want to cache any of the backend responses on the gateway, or if it is unlikely that a response from the target URL will allow caching through the Cache-Control header settings.

    Time to Live
    This option is similar to the Protocol option except it allows you to specify the amount of time that you want the successful response from the invoke or proxy to remain in the cache. Use this option only if you expect that responses from the target URL can be cached.

    The default value is Protocol.

    string
    Time to Live No Specifies the amount of time in seconds that the response stays in the cache. Applies only if the property Cache type is set to Time to Live. Enter a value in the range 5 - 31708800.

    The default value is 900.

    integer
    Cache key No Specifies the unique identifier of the document cache entry. If omitted, the entire URL string is used as the key. string
    Stop on error No Select the errors that, if thrown during the policy execution, cause the assembly flow to stop. If there is a catch flow configured for the error, it is triggered to handle the error thrown. If an error is thrown and there are no errors selected for the Stop on error setting, or if the error thrown is not one of the selected errors, the policy execution is allowed to complete, and the assembly flow continues. string

    Response object variable

    No The name of a variable that will be used to store the response data from the request. By default, the invoke response, that is the body, headers, statusCode and statusMessage, is saved in the variable message. Use this property to specify an alternate location to store the invoke response. This variable can then be referenced in other actions, such as Map.
    Note: If you want the response to be saved in message, leave the Response object variable property blank, do not supply the value message.
    string
  6. Specify a version for the policy by clicking the Source icon OpenAPI Source icon, and completing the version section of the policy YAML. For example:
    execute:
      - invoke:
          version: 1.0.0
          title: invoke
      ...
    You must specify a version for the policy that is compatible with the gateway that you are using. When the API is published, if the version is incompatible with the gateway, a validation error is thrown that specifies the available versions.
  7. Click Save.

Example

- invoke:
          version: 1.0.0
          title: get the account status
          timeout: 60
          verb: POST
          cache-response: time-to-live
          cache-ttl: 900
          stop-on-error:
            - ConnectionError
            - OperationError
          tls-profile: MyTLSProfile
          target-url: https://example.com/accounts/{id}?status={status}
          username: MyUser
          password: MyPassword