1

I'm trying to create an endpoint at gateway that will call multiple service calls and combine them in one response. Is that possible with express-gateway?

This is my gateway.config.yml.

http:
  port: 8080
admin:
  port: 9876
  host: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/ip'
  uuid:
    host: localhost
    paths: '/uuid'
  agent: 
    host: localhost
    paths: '/user-agent'

serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
  uuid:
    url: 'https://httpbin.org'
  agent:
    url: 'https://httpbin.org'    
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  default:
    apiEndpoints:
      - api
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
      - key-auth:
      - proxy:
          - action:
              serviceEndpoint: httpbin 
              changeOrigin: true
  default-1:
    apiEndpoints:
      - uuid
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
      - key-auth:
      - proxy:
          - action:
              serviceEndpoint: uuid 
              changeOrigin: true            
  default-2:
    apiEndpoints:
      - agent
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
      - key-auth:
      - proxy:
          - action:
              serviceEndpoint: agent 
              changeOrigin: true

Basically, I want to combine all of declared serviceEndpoints to one path. Let say I trigger /ip , it will call 'api,uuid,agent' serviceEndpoints and combine them all to one response. Is that possible?

Crystalix
  • 11
  • 1
  • This was answered here: https://stackoverflow.com/questions/60260252/how-to-route-nodejs-requests-to-another-nodejs-application – Jennifer Elyse Nov 18 '21 at 20:25

2 Answers2

0

Express Gateway does not really support such scenario unfortunately. You're going to have to write your own plugin — but it is not going to be so easy.

Vincenzo
  • 1,549
  • 1
  • 9
  • 17
  • Vincenzo, could you please suggest me alternative framework for me which can support this senario? – Naresh Walia Jan 16 '20 at 09:29
  • I'm not really aware of anything at the moment and unfortunately gateways are not my main focus anymore, at the moment. – Vincenzo Jan 16 '20 at 11:24
0

There are multiple approaches suggested on this regard, which you can weigh based on your use-case, tech-stack, team & tech-skills and other variables.

  1. Write an aggregation service that calls other underlying service
  2. Let the Gateway perform the service aggregation, data formatting etc... The important aspect here is to ensure that you don't break the domain boundaries. Its highly likely/tempting to inject some domain logic at the gateway along with aggregation, so be very careful about it.
  3. Have a look at GraphQL libraries out there, which is good to expose on top of your standard REST apis and you can define the schema and define the resolvers.
Dharman
  • 30,962
  • 25
  • 85
  • 135
Abdul Vajid
  • 1,291
  • 1
  • 15
  • 25