LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Path Prefix Service

For the details of the middleware handler, please visit the PathPefixService document.

The PathPrefixService handler is one of the middleware handlers that are used to identify the service_id before calling the router handle to route the traffic to multiple downstream APIs.

This handler is simple without depending on the OpenAPI specification in the light gateway(LG) and light client proxy(LCP). It is suitable when all the backend APIs have a unique prefix in the request path.

For the handler configuration, please visit the PathPefixService document. The following is for the values.yml in a shared gateway with all other related configurations for the router feature.

Once you have configured the PathPrefixServiceHandler, you need to find a way to map the service_id in the header to a real host for the downstream API. There are several ways to do that with service discovery. If you are using light-portal for the registry and discovery, you can set up the service.yml with PortalRegistry.

If you know the static URLs for the downstream API, you can use the DirectRegistry in the service.yml for static routing. This can be easily converted to service discovery in the future.

Here is the example for the pathPrefixService.mapping.

pathPrefixService.mapping:
  /v1: com.networknt.petstore-1.0.0
  /gateway/Migration/1.0.0: Migration

Here is the example for the service.yml with DirectRegistry.

service.singletons:
  - com.networknt.registry.URL:
      - com.networknt.registry.URLImpl:
          protocol: https
          host: localhost
          port: 7080
          path: direct
          parameters:
            com.networknt.petstore-1.0.0: https://localhost:9443
            Migration: http://dev-webservices.networknt.com
  - com.networknt.registry.Registry:
      - com.networknt.registry.support.DirectRegistry
  - com.networknt.balance.LoadBalance:
      - com.networknt.balance.RoundRobinLoadBalance
  - com.networknt.cluster.Cluster:
      - com.networknt.cluster.LightCluster
  - com.networknt.utility.Decryptor:
      - com.networknt.decrypt.AESDecryptor

You can see there are two serviceIds that map to two different hosts in the parameters.

For the router.yml, we might need to rewrite the URL to the path that the target server specification defined.

# router.yml
router.maxRequestTime: 5000
router.urlRewriteRules:
  - /v1/market(.*)$ /dev-test-ns/market/v1/market$1
  - /v1/pets(.*)$ /dev-test-ns/petstore/v1/pets$1
  - /gateway/Migration/1.0.0(.*)$ /1.0.0/Migration$1

For a running example, you can find it at https://github.com/networknt/light-gateway/tree/master/config/shared-gateway

  • 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
“Path Prefix Service” was last updated: November 20, 2022: fixes #347 add PathPrefixServiceHandler documents (ac1ebea)
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