Response transformation

This policy specifies the properties required to transform response messages from native APIs into a format required by the client.

The Response transformation transformations include Header transformation, Status transformation, Payload transformation, and Advanced transformation. You can configure conditions according to which the transformations are executed.

In IBM API Studio, this policy is identified by the kind TransformResponse.

Example of a Response processing policy in code view:

kind: TransformResponse
apiVersion: api.ibm.com/v2
metadata:
  name: response-processing
  version: 1.0
  namespace: wm_project
  tags:
    - iden
spec:
  condition: (${response.headers.test} equals test1) or (${response.headers.test}
    notEquals ${response.payload.jsonPath[$.customer.name]})
  transformations:
    set:
      - key: ${response.headers.h2}
        value: test-header-value
      - key: ${response.query.q2}
        value: ${response.path.name}
    setStatus: # Introduced for Response Processing
      code: 400
      message: Invalid request
    setPayload:
      content-types:
        - application/json: |
            {
                "empid":"1"
            }
        - application/xml: |
            <test></test>
        - text/plain: |
            "This is a plain content"
      defaultContentType: application/xml
      xsl:
        - feature:
            - name: http://javax.xml.XMLConstants/feature/secure-processing
              value: true
          $path: format.xsl
    remove:
      - ${response.query.q1}
      - ${response.path.mki}
    namespaces:
      - prefix: ps1
        URI: http://test.com
      - prefix: ps2
        URI: http://test2.com
    webMethodsISService:
      - $ref: wm_project:webMethodsISService:1.0 # refer

For the TransformResponse policy kind, configure these specifications:

Code view Form view Description
condition Conditions

Conditions are used to specify when the policy is run. You can add multiple conditions with logical operators. Provide the condition in the format: {set} operator {value} condition {set} operator {value}

You can configure the following conditions:

  • Transform the requests that comply with all the configured conditions in the code view by using and, or in the form view by selecting the AND option.
  • Transform the requests that comply with any one configured condition in the code view by using or, or in the form view by selecting the OR option.

You can use the following operators to add conditions.

  • Equals
  • Equals ignore case
  • Not equals
  • Not equals ignore case
  • Contains
  • Not Contains
  • Exists
  • Not Exists
  • IP Range
  • Greater Than
  • Lesser Than
transformations Transformation configuration

Specifies the response processing parameters.

You can configure the following under transformations in code view and Transformation configurationin the form view.

  • set. Specifies the header transformation to be configured for the responses received from the native API. You can add or modify header transformation parameters by providing the following information. This is a key value pair. Provide the key as a variable type with syntax. Provide the value as a plain value or value with a syntax.
  • setStatus. Specifies the status transformation to be configured for the responses received from the native API. Provide the following information:
    • code. Specifies the status code that is sent in the response to the client. For example if you want to transform status code as 201, provide 201 in the Code field.
    • message. Specifies the Status message that is sent in the response to the client. For example You have submitted successfully can be used to transform the original OK status message.
  • setPayload. Specifies the payload transformation to be configured for incoming requests.. Use the Payload transformation section to set the payload. You can provide one of the following values:
    • content-types. Specifies the content-type of payload, to which you want to transform. You can specify one of the following content types: application/json, application/xml, text/plain.
  • xsl. You can specify one or more transformation files that determine how the payload is modified before it’s sent or processed.

    In the form view, use the XSLT document section for this configuration.

    • $path. Specifies the location of the XSL transformation file. IBM API Studio reads the file from the given path and applies the defined transformation rules.
    • feature. Lists one or more transformation features as name-value pairs. The name must specify a valid feature, such as http://javax.xml.XMLConstants/feature/secure-processing, and the value must be set to true or false.

    You can include multiple XSL entries under setPayload to apply different transformations based on your configuration.

  • remove. Specifies which field to remove from the request.
namespaces Namespace

Configure the metadata for the message configuration request in form view under the Transformation metadata tab.

In the code view, under namespaces, configure the prefix and URI.

In the form view under Transformation metadata tab, click the Add namespace button to specify the optional Namespace prefix and Namespace URL.