- 
                Notifications
    You must be signed in to change notification settings 
- Fork 44
requestBodyTransformer
        thiagobustamante edited this page Jul 5, 2017 
        ·
        2 revisions
      
    This interceptor needs to receive an options object containing the jsonata expression to be applied for transformation.
This interceptor requires that you set parseReqBody: true in your proxy configuration.
The following configuration maps all endpoints from http://httpbin.org and applies a transformation on the request for the operation POST on path /post (POST http://httpbin.org/post).
---
name: TestInterceptedAPI
version: 1.0.0
path: "/requesttransform"
group:
- id: Group1
  description: Endpoints Group One
  member:
  - path:
    - post/
    method:
    - POST
proxy:
  target:
    host: http://httpbin.org
  parseReqBody: true
  timeout: five seconds
  interceptor:
    request:
      - middleware:
          name: requestBodyTransformer
          options:
            expression: >
              {
                'name': Account.'Account Name',
                'myPurpleProducts':Account.Order[*].Product[Description.Colour='Purple']
              }
        group:
          - Group1
It will transform the original request received by the Gateway. For Example:
{
  "Account": {
    "Account Name": "Firefly",
    "Order": [
      {
        "OrderID": "order103",
        "Product": [
          {
            "Product Name": "Bowler Hat",
            "ProductID": 858383,
            "SKU": "0406654608",
            "Description": {
              "Colour": "Purple",
              "Width": 300,
              "Height": 200,
              "Depth": 210,
              "Weight": 0.75
            },
            "Price": 34.45,
            "Quantity": 2
          },
          {
            "Product Name": "Trilby hat",
            "ProductID": 858236,
            "SKU": "0406634348",
            "Description": {
              "Colour": "Orange",
              "Width": 300,
              "Height": 200,
              "Depth": 210,
              "Weight": 0.6
            },
            "Price": 21.67,
            "Quantity": 1
          }
        ]
      }
    ]
  }
}And our gateway configuration transforms it to:
{
  "name": "Firefly",
  "myPurpleProducts": [
    {
      "Product Name": "Bowler Hat",
      "ProductID": 858383,
      "SKU": "0406654608",
      "Description": {
        "Colour": "Purple",
        "Width": 300,
        "Height": 200,
        "Depth": 210,
        "Weight": 0.75
      },
      "Price": 34.45,
      "Quantity": 2
    }
  ]
}