Hi ALL,
We are migrating the following APIs from our Node.js stack to Apigee. In Node.js, these APIs are exposed with dynamic URL segments as shown below:
api/v1/:id/sample/:id2/private
api/v1/:id/getsample/:id2/public
api/v1/:id/testsample/:id2/private
We would like to expose these APIs with the same URL structure in Apigee.
Note: All APIs will be deployed within the same organization and environment in Apigee.
Could you please confirm if it's possible to maintain the same dynamic URL patterns in Apigee under these conditions?
Hi,
Very interesting question. Routing in Apigee uses a base path to determine which proxy to route the call to. Additional resources can follow the base path and the additional resources can be dynamic. However, the base path must be static.
Therefore, yes this is possible. There are a couple possible approaches. Both start with defining a proxy that has the basepath = "/api/v1". In a since, this proxy will act as the default proxy for all calls starting with /api/v1 that do not match another proxy, such as /api/v1/my-other-proxy.
The proxy with basepath /api/v1 can use the Extract Variables policy to extract the two IDs from the URI. Example:
<ExtractVariables continueOnError="false" enabled="true" name="extract-ids">
<DisplayName>Extract a portion of the url path</DisplayName>
<Source>request</Source>
<URIPath>
<Pattern ignoreCase="true">/{id1}/*/{id2}/*</Pattern>
</URIPath>
<VariablePrefix>urirequest</VariablePrefix>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>
curl https://{your-domain}/api/v1/my-id1/sample/my-id2/private
Once you have the IDs, I can see at least 2 approaches.
1) Use Conditional Flows to appropriately process each of the three URI options. See: https://cloud.google.com/apigee/docs/api-platform/fundamentals/what-are-flows#designingflowexecution...
2) Use call chaining to call proxies that represent each of the three URL options: /sample, /getsample, and /testsample.
In this model there are a couple import notes.
a) When using call chaining, each API call in the chain counts as an entitlement call.
b) The url structure for the three proxies will need to be different in order to address the basepath. For example they could be:
/api/v1/sample/{id2}/private?id={id1}
/api/v1/getsample/{id2}/public?id={id1}
/api/v1/testsample/{id2}/private?id={id1}
And AssignMessage would be used to reconfigure the Target URL appropriately.