Accessing flow variables in hosted targets

I'm using djv in my hosted target to validate the json data against a schema I have. I'm planning to call the proxy with hosted target from the actual proxy that has to do the json validation which will have the json in requestbody. How can i access this flow variable in the hosted target javascript file?(I will have the schema file loaded in the hosted target proxy, how do i transport the json in request body of proxy-A to hosted target proxy) and also is there a better way than using the hosted target for this validation - tv-4 has performance issues compared to ajv/djv AFAIK @Sai Saran Vaidyanathan @Dino-at-Google @Kurt Googler Kanaskie@Anil Sagar @ Google.

1 6 380
6 REPLIES 6

Hi @Krishna,

you can use manifest file where you can create environment variables and assign flow variables values to the correspondent environment variable which are accessible in the hosted target.

please take a reference from here - https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-reference#about-the-manifest-file

As you might be aware of, the apigee-access module cannot be used in hosted targets, so we need to rely on KVM and HTTP headers as per the below doc,

https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-faq#is-it-possible-to-work-around...

Your approach of using two proxies looks good. From Proxy A use a Service Callout(SC) policy to call Hosted Target(HT) proxy.

Within SC, use the Request Set Payload tags to send the request.content

<Request clearPayload="true" variable="myRequest">
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    
    <Set>
        
        <Payload contentType="application/json">
		{request.content}
	</Payload>  
    </Set>
</Request>

@Siddharth Barahalikar - Is it going to be considered as 2 API calls for 1 purpose which might be slow?

Well Krishna wants to validate the request payload before hitting the Target.

AFAIK djv/ajv/tv-4 are not supported in Apigee Rhino base Javascript policy. So we need to rely on Nodejs for JSON validation.

So I guess using two proxies is a good idea and anyway we can use LocalTargetConnection of Service Callout policy so Apigee will be making a localhost call to other proxy which would minize the latences.

Make sense. thanks for the detailing @Siddharth Barahalikar

@Ravindra Singh - Check this post