How to set a request variable in node js

We are trying to set some variables in the node js running as standalone on apigee using the below code

var http = require('http');
var apigee = require('apigee-access');

console.log('node.js application starting...');

var data = "do shashowania";
var crypto = require('crypto');
var hashdata=crypto.createHash('md5').update(data).digest("hex");


var svr = http.createServer(function(req, resp) {
apigee.setVariable(resp, "hashvar", hashdata);
resp.end('Hello, World!'+hashdata);
});

But it seems that the variable is not getting set ( as per the trace captured) could you please let me know if am doing something wrong here

Thanks,
Vednath

Solved Solved
0 6 3,177
1 ACCEPTED SOLUTION

@vednath pittala

Trace by default won't show all the response variables in response, It will show only if value is accessed in one of the policy. Your code works perfectly fine & variable is available in response flow. You just need to access variable in one of the policy to see it in trace.

See example policy that works for me & shows same in trace.

hello1-rev1-2016-07-07.zip

3102-screen-shot-2016-07-07-at-71129-pm.png

View solution in original post

6 REPLIES 6

@vednath pittala , Do you see any error in trace ?

@Anil Sagari dont see any error on the trace just that the variable is not getting set

@vednath pittala

Trace by default won't show all the response variables in response, It will show only if value is accessed in one of the policy. Your code works perfectly fine & variable is available in response flow. You just need to access variable in one of the policy to see it in trace.

See example policy that works for me & shows same in trace.

hello1-rev1-2016-07-07.zip

3102-screen-shot-2016-07-07-at-71129-pm.png

@Anil Sagar thanks anil adding the variable in policy resolved it

@Anil Sagar now am trying to use apigee cloud installation to do a service callout to nodejs. How do i use the context of the callout in the calling proxy. Attaching both the proxies for more clarityno-target-rev1-2016-07-07.zipnodejs-rev1-2016-07-07.zip where no target is the calling proxy and nodejs is the call out

PS bear with me for these rudimentary questions

Thanks,

Vednath

Great Question, Can you please post same as a new question for better context. Thanks. BTB, Any question is welcome in Apigee Community. There are nothing like "rudimentary questions".