LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Request Response Transformation

In this tutorial, we will demo the request and response transformation based on the rule engine in the light-gateway. The same handlers/interceptors can be used in the http-sidecar and any application built with the light-4j.

The demo will be based on three real use cases from our customers. We will show you the configuration and run the test with the petstore backend API to show you how the light-gateway works on the request and response chain.

The backend petstore API can be found here

The transformation rule implementations can found here

The light-gateway configuration for the demo can be found here

The light-example-4j default branch is the release; Here we are using the master branch, which is in sync with light-gateway master branch.

Prepare Environment

Follow the steps below:

You need to checkout the light-gateway and light-example-4j both master branch.

  • Build the light-example-4j/rest/petstore-maven-single

  • Build three modules under light-example-4j/rule folder.

  • Copy the rule jar files to light-gateway/rulesjar folder.

  • Start the petstore from command line.

  • Start the light-gateway from the IDE and add the rulesjar folder to the classpath.

Request Path Update from a Header

One of the project teams is migrating from SAG gateway to light-gateway, and they don’t want to update any of the consumers. The consumer’s request path needs to be rewritten to add a prefix from the HTTP header named context. Although the light-gateway router.yml gives you the capability to rewrite the request path based on the incoming request path, it doesn’t support rewriting the request path from the header values. To do that, we will leverage the interceptor RequestTransformerInterceptor

Response Structure Transform

One of the customers has defined a standard response structure with data and a list of notifications for error messages. When they upgrade all the services to this standard response, all existing native consumers are broken as they are expecting another format of the response. To avoid changing the native consumer, we have added a client proxy instance to the native consumer to transform the notifications response to something the native consumer is expecting.

REST to SOAP Transform

A team maintains a SOAP service and wants to rewrite it with REST. They have completed an open API specification but haven’t implemented it yet. A new consumer is onboarding to build a brand new application that wants to leverage the REST API instead of SOAP API. To support that, we put a light-gateway instance in between to translate the REST JSON request to SOAP XML request and SOAP XML response to REST JSON response.

SOAP Security Transform

One of our customers is accessing a Cannex Soap API from the corporate network with light-gateway via the generic ExternalServiceHandler. For all the consumers, they don’t need to set the security header in the SOAP request; the light-gateway intercepts the request body and adds security header with the correct credentials to access the Cannex. This is very similar to the above REST to SOAP request transformer; however, it is a little bit complicated as we are accessing an external service instead of internal services. For detailed configuration, please review this PR

  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Request Response Transformation” was last updated: September 21, 2022: fixes #341 Add a tutorial for Cannex Soap security to the request-response-transformation (6df4b96)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute