I have 3 operation in my proxy
GET - /users/{userId}
POST - /users
DELETE - /users/{userId}
Each of these operations needs to call 3 different target end points
GET - https://host/api/mobileapps/getUser
POST - https://host/api/mobileapps/createUser
DELETE - https://host/api/mobileapps/deleteUser
When I set the TargetEndpoint as follows:
<HTTPTargetConnection> <Properties/> <URL>hhttps://host/api/mobileapps</URL> </HTTPTargetConnection>
For each flow above, I can have a JS policy in my target end point, get the targetUrl using target.url flow variable. Append the target operation (getUser or createUser or deleteUser) to the target.url to hit the back end and get the response.
This approach works !!
Now what I am trying is to set the Target URL as Target Server
TargetServer name="target1"> <Host>host</Host> <Port>443</Port> <IsEnabled>true</IsEnabled> <SSLInfo> <Enabled>true</Enabled> </SSLInfo> </TargetServer>
In my Target end point:
<HTTPTargetConnection> <Properties/> <LoadBalancer> <Server name="target1"/> </LoadBalancer> <Path>/api/mobileapps</Path> </HTTPTargetConnection>
For each operation, how do I update the target.url as target.url flow variable does not work with Target server configurations (as discussed here)
Is there another approach ? I want to use Targetserver instead of URL so that is completely configuration based.
Solved! Go to Solution.
If your aim is to read the target server from a configuration instead of static URLs, you could use kvm to store the target hostname and then append the path based on your conditions above. The target server approach would not work in this case since the target url(or hostname) is not exposed for the targetserver entity. You can get the target server name using the variable: {loadbalancing.targetserver}
If you want to continue with the targetserver approach the only way would be to get the {loadbalancing.targetserver} variable and then make a mgmt api call to fetch the host and path using the GET /v1/o/{org}/e/{env}/targetservers/{target} and store that in cache, else the management layer dependency in your runtime will hurt your runtime apis. I would suggest the kvm approach for better scalability and ease of use.
If your aim is to read the target server from a configuration instead of static URLs, you could use kvm to store the target hostname and then append the path based on your conditions above. The target server approach would not work in this case since the target url(or hostname) is not exposed for the targetserver entity. You can get the target server name using the variable: {loadbalancing.targetserver}
If you want to continue with the targetserver approach the only way would be to get the {loadbalancing.targetserver} variable and then make a mgmt api call to fetch the host and path using the GET /v1/o/{org}/e/{env}/targetservers/{target} and store that in cache, else the management layer dependency in your runtime will hurt your runtime apis. I would suggest the kvm approach for better scalability and ease of use.
Thanks @arghya das - I eventually ended up using KVM and got it to work. It just gets a little complicated if I wanted the target server with Mutual Auth, etc.
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |