Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
jeremy_ma_usa
Advisor
Advisor
What: There is good blog already on how to deploy Dynamic Routing by Raghavendra, this blog is about how to pass the routing logic via payload or header instead of context path.

Why:  Having sender to code logic to context path is not always possible and you may want to keep the existing URI context path consistent and simple

How:

  1. Should familiarized the standard option as stated above blog

  2. In Mediation Policies, Add the Extract Variable policy

  3. Define the numerous target end points in APITargetEndPoint

  4. Deploy and Test


In the below example where I show routing to various wiki of countries base on payload country to direct wiki


 

2. Extract Variable from payload



<!-- Extract content from the request or response messages, including headers, URI paths, JSON/XML payloads, form parameters, and query parameters -->
<ExtractVariables async="true" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<!-- the source variable which should be parsed -->
<Source>request.content</Source>
<!-- Specifies the XML-formatted message from which the value of the variable will be extracted -->
<JSONPayload>
<Variable name="country">
<JSONPath>$.country</JSONPath>
</Variable>
</JSONPayload>
</ExtractVariables>

 

3. Define Various Target Endpoints


Unzip of APIProxy with TargeEndPoint Folder


targetf example file for France
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndPoint xmlns="http://www.sap.com/apimgmt">
<name>targetf</name>
<url>https://en.wikipedia.org/wiki/France</url>
<provider_id>NONE</provider_id>
<additionalAPIProviders/>
<isDefault>false</isDefault>
<properties/>
<faultRules/>
<preFlow>
<name>PreFlow</name>
</preFlow>
<postFlow>
<name>PostFlow</name>
</postFlow>
<conditionalFlows/>
<loadBalancerConfigurations>
<isRetry>false</isRetry>
<healthMonitor>
<isEnabled>false</isEnabled>
</healthMonitor>
</loadBalancerConfigurations>
</TargetEndPoint>

4. Deploy and review the mapping


Import Policy and View ProxyEndpoint


Inspect the variable:


Debug of the APIM Steps - Extract variable


 

Notice below POST call matching Step2 above of Condition String


Testing with Postman


 

 

Acknowledge:  Thanks to my colleague vinayak.adkoli to provided the first POC;

Additional references

  1. https://blogs.sap.com/2019/05/27/dynamic-routing-using-sap-cloud-platform-api-management/

  2. https://answers.sap.com/questions/13039092/extract-variable-from-soap-payload-in-api-proxy.html


1 Comment