Switch

Selects the first matching branch from multiple case conditions.

Use the Switch policy to evaluate multiple conditions and direct the flow to the matching branch. This helps you create region-based, client-based, or scenario-based routing.

For more information on the policy parameter descriptions, see DataPower Nano Gateway documentation.

Example of a Switch policy in code view.

kind: switch
apiVersion: api.ibm.com\v1
metadata:
  name: "data-masking-request-switch"
  version: 1.0
  namespace: sample
spec:
  cases:
    - condition: "$header('request', 'Content-Type') = 'application/json'" #json payload
      execute:
        - $ref:sample:redact-request-json
        - $ref:sample:remove-request-json
        - $ref:sample:transform-request-json
    - condition: "$header('request', 'Content-Type') in ['application/xml', 'text/xml']" #xml payload
      execute:
        - $ref:sample:redact-request-xml 
        - $ref:sample:remove-request-xml 
        - $ref:sample:simpleTransform-request-xml 
  otherwise: 
        - $ref:sample:redact-request-text 
        - $ref:sample:remove-request-text 
        - $ref:sample:transform-request-text