Maintain the target BasePath

Hello, I found this link  conversation  which I defined what happens in the Apigee pattern. I have a https://app.apigee.com/api/v1/product/search api, in BasePath /v1/product/ and the server I have https://app.server.com/api/search. The question is if you have any parameters that make you use the BasePath value on the target, for example: https://app.server.com/api/v1/product/search

0 1 71
1 REPLY 1

if you have any parameters that make you use the BasePath value on the target, for example: htt​ps://app.server.com/api/v1/product/search

I understand you would like Apigee to propagate the basepath from the Apigee API proxy to the upstream target. There is no "checkbox way" to tell Apigee to do that.

But Apigee is flexible enough that you can do it pretty easily. You need to construct the target url dynamically, to achieve this. This JS will do it

 

var u = context.getVariable("target.url");
var basepath = context.getVariable("proxy.basepath");
var newUrl = u + basepath;

// if want path suffix
newUrl += context.getVariable("proxy.pathsuffix");

// apply querystring
var qs = context.getVariable("request.querystring");
if (qs && qs != "") {
  newUrl += "?" + qs;
}
context.setVariable("target.url", newUrl);

 

You must attach that in the Target Request flow, somewhere.

If you don't ever have a querystring, then you could use AssignMessage:

 

<AssignMessage name='AM-targeturl'>
  <AssignVariable>
    <Name>target.url</Name>
    <Template>{target.url}{proxy.basepath}{proxy.pathsuffix}</Template>
</AssignMessage>

 

Given either one of those policies, with these conditions

URL inbound to Apigee htt​​​​ps://api.inbound-to-apigee.com/v1/product/search
basePath in Apigee proxy /v1/product
upstream URL configured in TargetEndpoint htt​​​ps://app.upstream.com/api

Apigee will invoke this URL at the upstream:

htt​​​ps://app.upstream.com/api/v1/product/search