PI REST Adapter – Consuming synchronous RESTful service
This blog is part of a collection of blog entries that shows architectural concepts and configuration of the SAP PI REST Adapter. We also added some sample scenarios to make it easier for you to understand how your scenario can be implemented using the PI REST Adapter.
If you haven’t done so far, best is to start with the very first blog PI Rest Adapter – Don’t be afraid within the blog series covering the concepts of the REST adapter. A complete list of all blog entries can be accessed from here PI REST Adapter – Blog Overview.
The current blog shows you along a sample scenario how to consume a synchronous RESTful service. In the example, the target URL is set dynamically by using variables.
We would like to determine geographic coordinates such as latitude and longitude based on a given address. This conversion is called geocoding. Here, we use Google’s Geocoding API in the following format:
The given address is set dynamically, the output format is JSON, and the sensor parameter equals false indicates that my application does not use a sensor to determine the location.
The address data type of my outbound interface simply contains street, city, country, region, and zip code. The particular address elements are used to dynamically set the address in the URL of the RESTful service call.
In the SAP Process Integration Designer perspective of the NetWeaver Developer Studio (NWDS), I have defined an Integration Flow with a SOAP sender channel and a REST receiver adapter, i.e., we expose the RESTful service as a SOAP web service. The format of the incoming request message is XML. The response from the Goecoding API is JSON which is converted to XML and passed back to the SOAP sender.
In the following I will focus on the configuration of the receiver adapter of type REST.
Configuring the REST receiver channel
On the Integration Flow double click on the receiver channel, and switch to tab REST URL below the Adapter-Specific settings. Enter the URL Pattern as follows using variables for street, city, country, and the sensor:
The address variables street_par, city_par, and country_par are replaced by the respective values in the request XML message. For each address part, I use an xpath expression to parse and read the respective values from the XML message. The boolean variable is replaced by the static value false.
Switch to tab REST Operation. Here, I have set the http operation of my RESTful service equals GET.
Finally, we need to define the format of the messages of the RESTful service. Switch to tab Data Format. Though I have maintained the format of the request message, the settings for the input message are actually superfluous since we do not provide any payload anyway. All information of the request is provided in the URL as seen above. However, entering the request format in the channel doesn’t harm.
The format of the response is expected to be in JSON, so I choose JSON as data format. Furthermore I need to convert the JSON to XML and hence select the Convert to XML check box.
Running the scenario
For testing the scenario, I used soapui. In the figure below you see that I have entered an address as request in XML format. The response contains the geographic coordinates of the given address.
I hope this blog was helpful to understand the consumption of RESTful services using the SAP PI REST adapter. If you like to learn more, check out the other blogs in the series, accessible from the main blog PI REST Adapter – Blog Overview.