Stop resource path from appending to Backend server

Not applicable

I am learning Apigee..

I have a proxy, that is calling default TargetEndpoint and pointed to httpbin.org. I am trying to add a resource /report to my proxy. Intention is send the requests for service v1/myservice/report to httpbin.org. Either using same Target Endpoint or a new one...However, the proxy seems to append the /report resource path to my backend (httpbin.org) requests. How to avoid this? What is the best way to do this?

Solved Solved
1 2 1,048
1 ACCEPTED SOLUTION

The behavior you describe is as designed and documented.

You can disable the behavior by setting a specific context variable: target.copy.pathsuffix

Set it to false, in the target flow.

You can do this with an assignMessage policy, or with a JavaScript policy. Examples follow.

Option 1:

<AssignMessage name='AM-TCPS-False'>
  <AssignTo createNew='false' type='request'/>
  <AssignVariable>
    <Name>target.copy.pathsuffix</Name>
    <Value>false</Value>
  </AssignVariable>
</AssignMessage>

Or, option 2:

<Javascript name='JS-TCPS-False'>
  <ResourceURL>jsc://setTargetCopyPathSuffixFalse.js</ResourceURL>
</Javascript>

and for the latter, here is the JS:

context.setVariable('target.copy.pathsuffix', false);

In either case, you must attach the policy in the Request Flow of the Target. Something like this:

<TargetEndpoint name="default">
    <Description/>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>http://httpbin.org</URL>
    </HTTPTargetConnection>
    <PreFlow name="PreFlow">
        <Request>
           <Step><Name>AM-TCPS-False</Name></Step>
        </Request>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
</TargetEndpoint>

Good luck!

View solution in original post

2 REPLIES 2

The behavior you describe is as designed and documented.

You can disable the behavior by setting a specific context variable: target.copy.pathsuffix

Set it to false, in the target flow.

You can do this with an assignMessage policy, or with a JavaScript policy. Examples follow.

Option 1:

<AssignMessage name='AM-TCPS-False'>
  <AssignTo createNew='false' type='request'/>
  <AssignVariable>
    <Name>target.copy.pathsuffix</Name>
    <Value>false</Value>
  </AssignVariable>
</AssignMessage>

Or, option 2:

<Javascript name='JS-TCPS-False'>
  <ResourceURL>jsc://setTargetCopyPathSuffixFalse.js</ResourceURL>
</Javascript>

and for the latter, here is the JS:

context.setVariable('target.copy.pathsuffix', false);

In either case, you must attach the policy in the Request Flow of the Target. Something like this:

<TargetEndpoint name="default">
    <Description/>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>http://httpbin.org</URL>
    </HTTPTargetConnection>
    <PreFlow name="PreFlow">
        <Request>
           <Step><Name>AM-TCPS-False</Name></Step>
        </Request>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
</TargetEndpoint>

Good luck!

This is great..thanks.