How to change the path?

mail-2
New Member

Hello!

So requests comes in:

GET [...].apigee.net/proxy/dog

With [...].apigee.net/proxy being the base path and /dog the suffix.

The target server is https://my-backend.com/

So far the above request would be routed to https://my-backend.com/dog

But I want that request to be routed to https://my-backend.com/cat!

The first idea is obviously https://docs.apigee.com/api-platform/reference/policies/assign-message-policy#set-path. But apparently that does not work and the recommended approach is to set target.url.

Like this:

# Proxy Endpoint / Conditional Flow for "dog"

<AssignVariable>
  <Name>targetUrl</Name>
  <Value>https://my-backend.com/cat</Value>
</AssignVariable>

# Target Endpoint / Post Flow:

<AssignVariable>
  <Name>target.url</Name>
  <Ref>targetUrl</Ref>
</AssignVariable>

Now my question is whether this is the recommended way to go for my use case?

I'm asking because having to handle the target server URL (https://my-backend.com/) there seems clumsy. Especially due to having to handle that target server URL as a global variable just to accomplish this feat - which as far as I can tell is pretty much as standard as it gets. Hence my confusion.

Cheers

Raffael

Solved Solved
0 1 3,522
1 ACCEPTED SOLUTION

Not applicable

I would suggest disabling the path suffix to get copied to target. To do that in the target endpoint preflow add an assign message/script policy to set

target.copy.pathsuffix = false.

This will stop forwarding /dog to the target. The next step is to add the path dynamically to the target server as below. set the dynamic value as per your condition.

    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="TargetServerABC"/>
        </LoadBalancer>        
        <Path>/v1/{dyanmic_path}</Path>
    </HTTPTargetConnection>

View solution in original post

1 REPLY 1

Not applicable

I would suggest disabling the path suffix to get copied to target. To do that in the target endpoint preflow add an assign message/script policy to set

target.copy.pathsuffix = false.

This will stop forwarding /dog to the target. The next step is to add the path dynamically to the target server as below. set the dynamic value as per your condition.

    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="TargetServerABC"/>
        </LoadBalancer>        
        <Path>/v1/{dyanmic_path}</Path>
    </HTTPTargetConnection>