-
Notifications
You must be signed in to change notification settings - Fork 43
header
Thiago da Rosa de Bustamante edited this page Jan 19, 2018
·
3 revisions
This router middleware can be used to route requests based on any request header 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 |
name | string | The request header name used by this router to take its decision. | true |
defaultTarget | string | The default destination (when the expected header is not present). | true |
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 heaeder value. The router will take this destination if the received header matches this value. | true |
Example:
---
name: TestHeaderAPI
version: 1.0.0
path: "/headerTest"
proxy:
target:
router:
middleware:
name: header
options:
name: 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 be routed to http://httpbin.org
when the request header apiVersion: 1
is provided http://httpbin.org/anything
when the request header apiVersion: 2
is provided.
If no header is provided, the request will be routed to http://httpbin.org
.