This plugin can be used when request from the API clients has to be routed to different upstream nodes based on the node number for which data is requested. This plugins extracts the parameter from incoming request either from header, query, path or request body and forms the upstream host dynamically. This plugin supports forming upstream host from below parameters -
- From request header
- From query params
- From path params
- From json or form-urlencoded request body
curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=node-details' \
--data 'url=https://nodenumber.org'
curl -i -X POST \
--url http://localhost:8001/services/node-details/routes \
--data 'paths[]=/anything' \
--data 'strip_path=false'
curl -i -X POST \
--url http://localhost:8001/services/node-details/plugins/ \
--data 'name=set-target-host' \
--data "config.upstream_host=nodenumber.org" \
--data "config.string_to_replace_from_host=nodenumber" \
--data "config.header=node"
curl -i 'http://localhost:8000/anything' --header 'node: httpbin'
Here plugin will read node header value and it will replace nodenumber string from hostname with this value. Final upstream hostname formed in this example will be httpbin.org
curl -X PUT http://localhost:8001/services/node-details/plugins/{plugin_id} \
--data 'name=set-target-host' \
--data "config.upstream_host=nodenumber.org" \
--data "config.string_to_replace_from_host=nodenumber" \
--data "config.query_arg=node"
curl -i 'http://localhost:8000/anything?node=httpbin'
curl -i -X PUT http://localhost:8001/services/node-details/plugins/{plugin_id} \
--data 'name=set-target-host' \
--data "config.upstream_host=nodenumber.org" \
--data "config.string_to_replace_from_host=nodenumber" \
--data "config.body_param=node"
curl -i 'http://localhost:8000/anything' \
--header 'Content-Type: application/json' \
--data-raw '{
"node": "httpbin"
}'
curl -i 'http://localhost:8000/anything' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'node=httpbin'
curl -i -X PUT http://localhost:8001/services/node-details/plugins/{plugin_id} \
--data 'name=set-target-host' \
--data "config.upstream_host=nodenumber.org" \
--data "config.string_to_replace_from_host=nodenumber" \
--data "config.path_index=2"
curl -i 'http://localhost:8000/anything/httpbin'
Name | Email Id |
---|---|
Anup Kumar Rai | [email protected] |
Saravanan Periyasamy | [email protected] |