express-gateway-plugin-array-transformer

Express Gateway plugin for transforming array in request or response

Usage no npm install needed!

<script type="module">
  import expressGatewayPluginArrayTransformer from 'https://cdn.skypack.dev/express-gateway-plugin-array-transformer';
</script>

README

express-gateway-plugin-array-transformer

Plugin for express-gateway that allows for transformation of response body when the response is an array.

Based on Response Transformation policy that is built in to express-gateway. That policy only transforms the body if it's JSON, while this one transform array response body.

Installation

eg plugin install express-gateway-plugin-rewrite

Quick Start

  1. Ensure the plugin is included in system.config.yml file of your gateway. For example:
array-transformer:
  package: express-gateway-plugin-array-transformer

Note: if you install the plugin using eg plugin create, this will already be added.

  1. Add configuration to your gateway.config.yml file.
  policies:
      - array-transformer:
        - action:
            body:
              add:
                test: "'test'"
              remove:
                - hello
                - world

action.add: key-value pair to add to response body. The value can be a string (as above) or an expression. For example: test: req.body.rTest where rTest is a key in request payload.

action.remove: An array of keys to be removed.