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: 
former_member37862
Product and Topic Expert
Product and Topic Expert
This blog describes the Dynamic routing use case using SAP Cloud Platform API Management.

Dynamic routing helps to define multiple target endpoints for an APIProxy and also set the condition to select the target endpoint at runtime

The use case is to create an API Proxy which will route to different target endpoints at runtime depending on a defined condition.

We are going to create an APIProxy and define the following two target endpoints  :

The first step is to launch APIPortal and create an APIProxy using any one of the above urls as the target endpoint

Download the newly created APIProxy to define target endpoints and set conditions



 

There is a parent folder APIProxy with the following folder structure :



Open the folder APITargetEndPoint to define the target endpoints

There will be an XML file called default.xml, delete the default.xml file

Define target endpoints and add target endpoint definition files in APITargetEndPoint folder



Let's define the Categorries.xml to hit the target endpoint https://services.odata.org/V2/OData/OData.svc/  



As shown in the above screenshot, in the Categories.xml file provide a name to the target endpoint and set the backend URL

Similarly, define the ServiceCollection.xml to hit the target endpoint https://sapes5.sapdevcenter.com/sap/opu/odata/IWFND/CATALOGSERVICE

We have defined the TargetEndPoints, now let's add the condition using Route Rule

To define the Route Rule open the default.xml file present in the APIProxyEndPoint folder



As shown in the above screenshot, in the default.xml file provide a route rule name and set the Conditions

Route rule Categories checks the set condition proxy.pathsuffix MatchesPath "/Categories"

when the path suffix is /Categories, URL defined in the TargetEndPoint Categories will be hit at runtime

Similarly, define the Route rule ServiceCollection

Finally, open the API_Proxy_Name.xml (in this example APIProxy name is Multiple_Target_End_Point.xml)

Add the defined target endpoints in the targetEndPoints tag



 

Almost done, let's import the modified APIProxy zip and open the APIProxy in the APIPortal.



Go to Proxy EndPoint tab and add the Route Rules as shown in the above screenshot and save

 

Now to see how dynamic routing works, hit the APIProxy URL with pathSuffix /Categories

Response:



 

 

Validate the response, lets hit the target endpoint(backend URL) with pathSuffix /Categories

Response:



Both the responses match 🙂  APIProxy created successfully with multiple target endpoints..

Similarly hit the APIProxy & Target Endpoint(corresponding backend) URL with the path suffix /ServiceCollection and validate the response

 
4 Comments