Enterprise
October 23, 2020
4 min read

Transform Your Requests/Responses With the Kong Reedelk Transformer Plugin

Kong

Introduction

Creating an API contract and corresponding Kong service are often just the first steps in the API development process. More often than not, the upstream services that are invoked provide a different contract to the one presented to the API consumer. This is especially the case in larger organizations where enterprise applications offer their own out-of-the-box integration contracts. Likewise, you shouldn't expose the complexity of your upstream systems to your API consumer. So, what's the best way to transform these upstream/downstream requests into something that both sides can understand?

Enter Reedelk, a Kong Hub plugin partner, which provides a platform to develop API data integrations and transformations with a visual designer based on IntelliJ IDEA. Reedelk helps you boost your development productivity by providing pre-built components packaged in modules to get you up and running quickly. By simply dragging and dropping components onto the canvas, you can save a lot of time in comparison to writing code from scratch. Being component-oriented also improves the quality of your implementation due to reusability. There’s also the option of importing your OpenAPI Specification that you designed in Insomnia into Reedelk; this saves you time when building a new API or integration flow.

There are several components available, allowing you to work with different technologies and performing transformations, such as JSON, XML, MongoDB, Google Drive and RDBMS components. There’s the option to develop your own custom components for more ad-hoc requirements.

Running your integration flow alongside Kong is simple - either use a pre-built Reedelk Docker image or create your own. The Reedelk runtime is by design lightweight to meet the need for agile deployments and microservice oriented architectures. Administration is taken care of with a purpose-built console that shows you what you have deployed and where.

Integrating Kong With Reedelk Data Integration Platform

The Reedelk Transformer Plugin can be applied in the Kong upstream phase to transform data before invoking the upstream service or in the downstream phase to transform data returned by the upstream service before returning it to the API user.

The following figure shows the high-level architecture of the Reedelk Transformer plugin for Kong when configured in the downstream phase:

Fig 1: Kong Reedelk Transformer plugin high-level architecture – downstream phase

  1. An API user makes an HTTP request to a Kong route.
  2. Kong forwards the HTTP request to the upstream service.
  3. The upstream service sends the response back to Kong.
  4. The Reedelk Transformer Plugin intercepts the response payload and invokes a Reedelk REST flow using an HTTP POST request with payload containing the data returned by the upstream service.
  5. The Reedelk REST flow applies the transformation to the posted payload and returns the new payload back to the Reedelk plugin.
  6. The Reedelk plugin replaces the original response from the upstream service with the transformed payload from the Reedelk flow and Kong sends the response back to the API user with the new payload.

In the following example, a mobile banking application may need to display different information depending on whether the customer is a private person or a business account. Within the associated OpenAPI Specification, a discriminator is used to handle the various fields accordingly. To resolve this use case with Reedelk, we simply create a new flow, which transforms an incoming request from one JSON structure to another JSON structure according to the value of a JSON property named "customerType."

The Router Component in the flow checks the value of the "customerType" property from the original JSON payload coming from the upstream service: if its value is ‘business' the JSON is transformed in one structure, if its value is ‘private' the JSON is transformed in a different structure with only a subset of the original properties.

Fig 2: Reedelk Flow Designer displaying an integration flow to transform a JSON structure into another JSON structure based on a condition.

Once the Reedelk Transformer plugin for Kong is installed and properly configured, no additional configuration is required in order to integrate Reedelk with Kong and have Reedelk transform the payload passing through the Kong API gateway.

About the Author:

Allan is the co-founder of Reedelk together with his business partner Lorenzo. Allan spent the last twenty years working for large enterprises but now works on his integration platform Reedelk. He lives in Helsinki, the birthplace of Nokia, and is surrounded by many wonderful people. Allan is now working really hard to put his knowledge and passion to good use; please feel free to get in touch with him.

LinkedIn: www.linkedin.com/in/allan-knabe

Twitter: https://twitter.com/reedelk

Github: https://github.com/reedelk/reedelk-runtime