The Nano Gateway invoke policy reference is a set of tables. This post runs each option against a real backend, with the YAML from API Studio code view and the response the gateway sent back.

The companion post covers the switch policy. Several examples below use a switch to pick which invoke runs.

The test project

One API Studio project, one API called nano-invoke, one operation per invoke option. Every example below calls the same backend. It answers GET with 200 and a JSON body, and answers every other verb with 405. That makes the verb and statusException options easy to see.

This API is deliberately complex to showcase the different combinations and routing options available across the invoke flow:

ExtractIdentity, Authenticate, and Authorize enforce client credentials, followed by an OperationSwitch that routes each incoming path to its corresponding invoke configuration.

Every call goes to the published product URL with the client credentials of a subscribed application:

curl -s \
  -H "X-IBM-Client-Id: <client-id>" \
  -H "X-IBM-Client-Secret: <client-secret>" \
  "https://<product>-<catalog>-<org>.nanogw.<ingress-domain>/1.0.0/nano-invoke/basic"

Without valid credentials the same call returns 401 Unauthorized. I tested no credentials, a wrong ID, a wrong secret, an ID with no secret, a secret with no ID and empty headers. All returned 401.

Example 1: the minimal invoke

kind: Invoke
spec:
  endpoint:
    http:
      target:
        url: https://backend.example.com/identity-providers
        urlType: plain
        timeout: 60
        tlsClientProfile: tls-client-profile-catalog-default:1.0.0
        version: HTTP/1.1
      verb: GET

url is the only required field under target. Everything else is optional.

inputMessage and outputMessage are not set. The documentation says they default to request and response. The outgoing call is built from the inbound request, and the backend reply becomes the response the caller receives. The gateway passes the backend body straight through:

HTTP/1.1 200
{
    "total_results": 1,
    "results": [
        {
            "name": "default-idp-2",
            "title": "API Manager User Registry",
            ...

timeout is the time to wait for a reply from the endpoint, in seconds. The default is 20, so a 60 here is a deliberate choice. tlsClientProfile names the TLS profile used for the call to the backend. This project uses the catalog default profile so the gateway trusts the cluster ingress CA.

In code view, Studio writes the message options as input and output. The Nano Gateway reference page calls them inputMessage and outputMessage. They are the same options.

Example 2: the verb

verb takes GET, POST, PUT, DELETE, PATCH, HEAD or OPTIONS. If you leave it out, the invoke keeps the method of the incoming request.

The /verb operation uses a switch on a query parameter to run one invoke per verb. The seven invoke policies are identical except for verb:.

kind: Switch
spec:
  cases:
    - condition: "$queryParameter('request','verb') = 'POST'"
      execute:
        - $ref: nanogw-policy-samples:nano-invoke-verb-post:1.0.0
    - condition: "$queryParameter('request','verb') = 'PUT'"
      execute:
        - $ref: nanogw-policy-samples:nano-invoke-verb-put:1.0.0
    # DELETE, PATCH, HEAD and OPTIONS follow the same pattern
  otherwise:
    - $ref: nanogw-policy-samples:nano-invoke-plain:1.0.0   # GET
curl ... "https://<gateway-host>/1.0.0/nano-invoke/verb?verb=POST"
HTTP/1.1 405
content-type: application/json

{
  "status": 405,
  "message": [
    "Not Allowed"
  ]
}

That is the backend’s own 405 and body. By default the invoke forwards whatever status the backend returns. Results for all seven verbs plus a call with no verb parameter:

Request Invoke verb Result
verb=GET GET 200, identity provider list
no verb parameter GET (otherwise branch) 200, identity provider list
verb=POST POST 405, JSON body
verb=PUT PUT 405, JSON body
verb=DELETE DELETE 405, JSON body
verb=PATCH PATCH 405, JSON body
verb=HEAD HEAD 405, no body
verb=OPTIONS OPTIONS 405, JSON body

In this project every operation is a GET, so leaving verb out would also send a GET. To see the keep-the-method behaviour you need an operation that accepts something else.

Example 3: urlType

urlType controls how the url string is read. The reference lists four values: plain, variables, distributedVariable and jsonata. I tested the first three. All three hit the same backend and return the same body.

plain

The URL is used as written. This is Example 1.

variables

$(name) in the URL is replaced with an assembly variable. A set policy defines the variable first:

kind: Set
spec:
  variable:
    name: identityProvidersPath
    value: '/api/cloud/provider/identity-providers'

Then the invoke uses it:

kind: Invoke
spec:
  endpoint:
    http:
      target:
        url: https://backend.example.com$(identityProvidersPath)
        urlType: variables
        timeout: 60
        tlsClientProfile: tls-client-profile-catalog-default:1.0.0
        version: HTTP/1.1
      verb: GET

The switch that routes this case runs both policies in order:

- condition: "$queryParameter('request','urlType') = 'variables'"
  execute:
    - $ref: nanogw-policy-samples:nano-invoke-set-path-var:1.0.0
    - $ref: nanogw-policy-samples:nano-invoke-urltype-variables:1.0.0

jsonata

The url is evaluated as a JSONata expression. Do not wrap the whole expression in quotes unless you want a literal string. The expression here is a concatenation of two string literals, so each literal has its own single quotes:

url: "'https://backend.example.com' & '/api/cloud/provider/identity-providers'"
urlType: jsonata

The reference page gives a more useful example. It builds the URL from the incoming request path with $relativeUrl('request'):

url: "'https://backend.example.com/fetch_bank_details' & $relativeUrl('request')"
urlType: jsonata

I did not run that one. It is the documented pattern, and $relativeUrl is in the supported JSONata function list.

distributedVariable reads the URL from a distributed variable. I did not test it.

Example 4: the HTTP version

version takes HTTP/1.0, HTTP/1.1 or HTTP/2. If you leave it out, the invoke keeps the version of the incoming request.

Three invoke policies, identical except for version:, sit behind a switch:

kind: Switch
spec:
  cases:
    - condition: "$queryParameter('request','version') = 'HTTP/1.0'"
      execute:
        - $ref: nanogw-policy-samples:nano-invoke-version-10:1.0.0
    - condition: "$queryParameter('request','version') = 'HTTP/2'"
      execute:
        - $ref: nanogw-policy-samples:nano-invoke-version-20:1.0.0
  otherwise:
    - $ref: nanogw-policy-samples:nano-invoke-version-11:1.0.0

All three returned 200 with the same body.

Observed on my lab cluster, not documented: the backend sits behind an OpenShift router that does not negotiate HTTP/2. openssl s_client -alpn h2 reported “No ALPN negotiated”. The HTTP/2 invoke still returned 200, so the gateway presumably fell back to a protocol the backend supports. Do not rely on that without testing against your own backend.

Example 5: keep the backend response out of the caller response

outputMessage stores the backend reply in a named message instead of response. Any name other than request and response creates an intermediate message. Nothing reaches the caller until a later policy copies it there.

Four policies run for /output-message:

- $ref: nanogw-policy-samples:nano-invoke-intermediate:1.0.0
- $ref: nanogw-policy-samples:nano-invoke-parse-result:1.0.0
- $ref: nanogw-policy-samples:nano-invoke-copy-result:1.0.0
- $ref: nanogw-policy-samples:nano-invoke-copy-result-content-type:1.0.0

The invoke writes to healthCheckResult. In code view the option is output:

kind: Invoke
spec:
  endpoint:
    http:
      target:
        url: https://backend.example.com/identity-providers
        urlType: plain
        timeout: 60
        tlsClientProfile: tls-client-profile-catalog-default:1.0.0
        version: HTTP/1.1
      verb: GET
  output: healthCheckResult

The parse policy reads the body of healthCheckResult as JSON. With no output message set, parse stores the result back into its input message:

kind: Parse
spec:
  documentType:
    json: {}
  input: healthCheckResult

A set policy copies the body into response:

kind: Set
spec:
  valueType: jsonata
  messageBody:
    messageName: response
    value: "$string($body('healthCheckResult'))"

$body(message_name) is in the supported JSONata function list and returns the body of the named message.

A second set puts the content type on the response:

kind: Set
spec:
  messageHeader:
    action: set
    headerName: Content-Type
    messageName: response
    value: 'application/json'

The caller gets the same body as Example 1:

HTTP/1.1 200
content-type: application/json

{"total_results":1,"results":[{"name":"default-idp-2","title":"API Manager User Registry", ...

Observed on my lab cluster, not documented: three details mattered. $body() could not read the invoke output until the parse policy had run. The set policy needed valueType: jsonata, because I saw value treated as a literal string without it. And $string() was needed around $body(). I have not found any of these stated in the product documentation. The default valueType of the set policy is also undocumented. I believe it is plain.

Example 6: statusException

By default the invoke forwards a 405 and the backend body. statusException changes that. When the backend status matches a pattern, the invoke throws an error. The reference page says it throws a CustomError with the response code and the canonical message.

kind: Invoke
spec:
  endpoint:
    http:
      statusException:
        - pattern: '405'
      target:
        url: https://backend.example.com/identity-providers
        urlType: plain
        timeout: 60
        tlsClientProfile: tls-client-profile-catalog-default:1.0.0
        version: HTTP/1.1
      verb: POST

Same backend, same POST, same 405. Compare the result with the pass-through in Example 2:

HTTP/1.1 405
Method Not Allowed

The backend JSON body is gone. The gateway answered with the canonical status text. The throw policy completes the assembly with an error result, so nothing after the invoke runs. Wrap the invoke in a try with a catch block if you want to return your own error instead.

pattern is three characters, each a digit or *. It must match ^[0-9\*]{3}$. So '5**' should cover every 5xx. I only tested an exact '405'.

Summary

  • url is the only required target field. Add timeout and tlsClientProfile for anything real.
  • Leave verb and version out to keep the incoming request values. Set them when the backend needs something different.
  • Use variables or jsonata for URLs built at run time. Use plain for everything else.
  • Use output in code view when you need to inspect or reshape the backend reply before the caller sees it.
  • Use statusException when a backend status should be an error in the assembly, not a pass-through.

Limitations and Notes

  • Tested on a DataPower Nano Gateway with the API Connect 12.1 documentation set. Check the version you run.
  • Not tested: distributedVariable, the $relativeUrl URL, wildcard statusException patterns, cache, inputMessage set to a custom message, chunkedUpload, compressRequest, decompressResponse, followRedirects and persistentConnections.
  • The Nano Gateway only validates JSON schemas. A response in the OpenAPI document with a non-JSON media type and a schema fails at publish time. This is why the status-exception response in my OpenAPI document has no content block.
  • Republishing a product returns 503 for a short time while the runtime pods restart. The Nano Gateway publish behaviour page covers the mitigation.