Passing parameter in nodejs hosted target

I have used a nodejs script which parses through proxy in a orge and return the virtual host associated with the proxy. That script uses parameter like username, password, org etc as input. I want to deploy the script as nodejs hosted target in apigee. How i can pass those parameters in nodejs hosted target 

@dino 

Solved Solved
0 5 320
1 ACCEPTED SOLUTION

You can pass parameters to a Hosted Target in any of these ways: 

  • query parameters
  • form parameters (application/x-www-form-urlencoded) 
  • headers
  • path segments (eg /inquire/ORGNAME/ENVNAME/PROXY
  • Parameters encoded in a payload (like XML or JSON)

I guess the function of the script is sort of independent of the options for how to submit parameters to it. If it's a hosted target, it accepts a web request, and that means you can use any of the usual mechanisms for passing information or parameters into it.

I would caution you though, to take care with your plan.  From your phrase "parses through proxy in an org" ,  I am inferring that the script invokes the Apigee administrative API to collect that information.  And did you know that invoking the Admin API from within a proxy is an anti-pattern?  Be careful when you do this.

View solution in original post

5 REPLIES 5

You can pass parameters to a Hosted Target in any of these ways: 

  • query parameters
  • form parameters (application/x-www-form-urlencoded) 
  • headers
  • path segments (eg /inquire/ORGNAME/ENVNAME/PROXY
  • Parameters encoded in a payload (like XML or JSON)

I guess the function of the script is sort of independent of the options for how to submit parameters to it. If it's a hosted target, it accepts a web request, and that means you can use any of the usual mechanisms for passing information or parameters into it.

I would caution you though, to take care with your plan.  From your phrase "parses through proxy in an org" ,  I am inferring that the script invokes the Apigee administrative API to collect that information.  And did you know that invoking the Admin API from within a proxy is an anti-pattern?  Be careful when you do this.

I am using below script to find vhost and I am passing parameter in command line so will it possible to same in hosted target?

https://github.com/DinoChiesa/apigee-edge-js-examples/blob/main/findVhosts.js

No you can’t do that. That script is a command line tool.  The hosted target must be an http server app. You’d need to re-work things significantly. 

what problem are you really trying to solve?

Actually i am trying to make a api which returns proxy names by making a GET call with environment name and vhost name in query param which can be used to display the same in monitoring dashboard 

If I were doing this I would model the logic that calls the management API..... as a service. Deploy it into AppEngine as a nodejs app.  Then invoke THAT from within the Apigee proxy. 

You could re-use _some_ of the logic that is present in the findVhosts.js script you cited. But you'd need to fit that logic into a server app.