Skip to content
Thiago da Rosa de Bustamante edited this page Jan 19, 2018 · 3 revisions

This router middleware can be used to route requests based on a request query parameter provided by the user.

The middleware needs to receive an options object containing the possible targets for the routed API. This object contains the following properties.

Property Type Description Required
destinations RouterDestination[] A list with possible destinations for the API request. true
param string The query parameter name used by this router to take its decision. true
defaultTarget string The default destination (when the expected param is not present). true

RouterDestination

Configure a single destination for the router. Can contain the following properties:

Property Type Description Required
target string A target destination. true
value string The expected parameter value. The router will take this destination if the received parameter matches this value. true

Example:

---
name: TestQueryAPI
version: 1.0.0
path: "/queryTest"
proxy:
  target:
    router:
      middleware:
        name: query
        options:
          param: apiVersion
          defaultTarget: http://httpbin.org
          destinations: 
            - target: http://httpbin.org
              value: '1'
            - target: http://httpbin.org/anything
              value: '2'
  timeout: 5000

This configuration will make requests to http://<gatewayaddress>/queryTest?apiVersion=1 be routed to http://httpbin.org and requests to http://<gatewayaddress>/queryTest?apiVersion=2 be routed to http://httpbin.org/anything.

If no parameter is provided, the request will be routed to http://httpbin.org.

Clone this wiki locally