Request transformation

The Request transformation policy helps configure several transformations on the request messages from clients into the correct format before it is submitted to the native API.

The transformations include Header, Query Parameter, Path Parameter transformation, HTTP Method transformation, Payload transformation, and Advanced transformation. You can configure conditions according to the transformations being run.

In IBM API Studio, the kind TransformRequest identifies the Request Processing policy.

Example of a Request Processing policy in code view.

kind: TransformRequest
apiVersion: api.ibm.com\v1
metadata:
  name: request-processing-policy
  version: 1.0
  namespace: sample
spec:
  condition: (${request.httpMethod} equals POST) or (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})
   # other operators include Equals, Equals ignore case, Not equals, Not equals ignore case, Contains, Not Contains, Exists, Not Exists, IP Range, Greater Than, Lesser Than
  transformations:
    set:
      - key: ${request.headers.name}
        value: customerName
    setMethod: POST  # GET | PUT | POST | HEAD | PATCH 
    setPayload:
	  content-types:
		 - application/json: |
			{
				"empid":"1"
			}
		- application/xml : |
			<test></test>
		- text/plain : |
			 "This is a plain content"
      xsl:
        - feature:
            - name: http://javax.xml.XMLConstants/feature/secure-processing
              value: true
          $path: /home/resources/xslt.xsd
          content: sdsd
    remove:
      - ${request.query.q1}
      - ${request.path.mki}
    namespaces:
      - prefix: ps1
        URI: http://test.com
      - prefix: ps2
        URI: http://test2.com

For the TransformRequest 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 in the code view and in the form view by using the Add condition button, which is optional.

  • 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 request processing parameters.

You can configure the following under transformation in code view and Transformation configuration tab in the form view.

  • transformations. You can apply the following transformations:
    • set. Specifies the Header, Query, or path transformation to be configured for incoming requests. You can add or modify header, query, or path transformation parameters by providing the following information. This transformation 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. You can provide multiple key value pairs.
    • setMethod. Specifies the method transformation to be configured for incoming requests. You can use the following values: CUSTOM, GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS.
    • setPayload. Specifies the payload transformation to be configured for incoming requests. 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.

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 Namespace prefix and Namespace URL, which are both optional fields.