Management API to create Target URL for Node JS

Hi

We have a proxy with a Node Target. Node Target URL will hit another API endpoint say n number of times with different parameters and collate the response.

Based on different environments (prod, dev, qa etc. ) the IP address/host that the API hit will change though relative path remain the same.

We want to use configurations

We came across two approaches to handle the same -

a. Store the hostname/IP as a KVM property and retrieve the same in Node JS ( Though we already have the target server defined with the same value so it will be a repetition and have to be done for all environments)

b. Use management api to retrieve the target server information based on environment and organisation information in Node JS.

https://api.enterprise.apigee.com/v1/organizations/a377-eval/environments/prod/targetservers/cms

This will give output like

<code>{
  "host": "135.185.15.18",
  "isEnabled": true,
  "name": "cms",
  "port": 80
}

From here we can form a url after extracting the values from JSON above and then use the same in Node JS to form a . target endpoint.

Should we go with a) or b)

Is b) an efficient approach as it introduces an extra call. Is there a way to cache or optimize as the no of calls may be substantial in number. Will it be better to do this in node target or we should use a service callout and then pass the response to node through context variable.

Any inputs are appreciated.

Thanks,

Aakash

0 4 286
4 REPLIES 4

From a performance perspective, both options are the same. Using Node.js to retrieve values from the KVM are effectively MGMT API calls behind the scenes. The real question that you need to answer is "Will these values change at runtime?" Based on answering that, you can figure out if you can get these values once at startup or if they need to be accessed for each request. Just know that if it's the latter, you might look into using the proxy definition to stuff these values in the request headers to avoid an MGMT call to get them from Node.js.

I hope this helps.

these values as i mentioned will be target server ip/names so they will vary for each environment but stays the same for a proxy depending on the env-context it is executing. thanks for your inputs.

Using a KVM to store the host value, albeit redundant with your target server, is the right thing to do for a number of reasons:

  • Its fast, KVMs use caching
  • It easily fits into your CI / CD as KVMs can be deployed via maven.
  • Calling management APIs during runtime APIs is bad practice and doesn't scale as your API traffic does.

Okay thanks for your inputs. Can see a difference of 180 ms on service call out to management api to retrieve host/port. Will try to see impact on sizeable requests.