Hi,
I noticed in this https://cloud.google.com/apigee/docs/api-platform/reference/policies/http-modifier-policy#set-path
This element isn't currently working as designed to override/rewrite a proxy's target URL.
Sometimes you may need to send a message to a URL other than the URL defined in an API proxy's TargetEndpoint. (You can't override target.url in the ProxyEndpoint, because Apigee sets the variable in the TargetEndpoint).
Is there an alternate way to do this?
Thanks,
Kyle
Solved! Go to Solution.
Just to follow up, Using a JS policy to update target.url worked.
if (context.flow=="TARGET_REQ_FLOW") {
var target_url = context.getVariable("property_set_webhook_lookup");
context.setVariable("target.url", "https://" + target_url + "/");
}
This element isn't currently working as designed to override/rewrite a proxy's target URL.
I'm sorry but "it isn't working" is not a complete enough description to get help.
What are you trying? where is the policy attached?
what did you observe? Specifically.
What were you expecting to observe?
Is there an alternate way to do this?
Sure. Assign to target.url , via AssignMessage/AssignVariable, attached to the TargetEndpoint / Request flow. (Google for it here on community, you'll find example configurations)
But if you are trying HttpModifier I guess you might not have a "Compehensive" environment and maybe the AssignMessage policy type is not available to you.
Hi,
"This element isn't currently working as designed to override/rewrite a proxy's target URL."
is a quote from the documentation itself.
That said, I definitely could have include more information. I am mapping incoming requests to backend cloud functions by extracting the path from the incoming request, mapping it via property file to a target endpoint, and then setting that endpoint as the TargetProxy. So if my path is `https://host/<basepath>/<endpoint>` then `<endpoint>` is extracted and used to look up the target endpoint <dynamic_endpoint>
I'm doing this by using ExtractVariable (ProxyEndpoint PreFlow)
<URIPath>
<Pattern ignoreCase="false">/{endpoint}</Pattern>
</URIPath>
and AssignMessage (via PropertySetRef) to lookup <dynamic_endpoint> from a property file (ProxyEndpoint Flows). <dynamic_endpoint> is then assigned as the target URL :
<HTTPTargetConnection>
<URL>https://{dynamic_endpoint}</URL>
</HTTPTargetConnection>
Just to follow up, Using a JS policy to update target.url worked.
if (context.flow=="TARGET_REQ_FLOW") {
var target_url = context.getVariable("property_set_webhook_lookup");
context.setVariable("target.url", "https://" + target_url + "/");
}
I'm glad you solved it.
@kcacciatore wrote:
The docs say that target.url can't be overwritten via AssignMessage, but via Javascript Policy,
hmmm. In fact, it is possible for a proxy to set target.url with AssignMessage. I think the documentation should be amended to be clearer. JS is one way to do it. AssignMessage is another.
EDIT:
I've gotten the documentation updated.
https://cloud.google.com/apigee/docs/api-platform/reference/variables-reference#target
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |