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:
You can use the following operators in the code view and in the form view by using the Add condition button, which is optional.
|
transformations |
Transformation configuration |
Specifies the request processing parameters. You can configure the following under
|
namespaces |
Namespace |
Configure the metadata for the message configuration request in form view under the Transformation metadata tab. In the code view, under 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. |