REST Adapter with Multiple Operations in SAP PI

This blog will show how to use REST Adapter with Multiple operations in SAP PI. Here we will expose the API with multiple operations for which REST sender will be used.

Flow:

REST Adapter with Multiple Operation Flow

As shown in flow diagram PI will expose the REST API with 2 operation addition & subtraction.

I will recommend going through the Sync/Async scenario using the REST adapter before starting into multiple operation configurations using the REST adapter. That will provide a good REST adapter background.

Async Scenario using REST Adapter Scenario in SAP PI

Sync Scenario using REST adapter in SAP PI

ESR Steps

In this section, we will create all the ESR objects

If you know how to create the ESR objects skip to REST adapter configuration.

  1. Create DT, MT.
  2. Create an outbound service interface – with multiple operations
  3. Create Inbound interfaces
  4. Mapping

The following Objects will be created.

REST Adapter in SAP PI

Most of the objects above are easy, but the Outbound service interface is a bit different.

This will be created with multiple operations as shown below.

  • Add
  • Sub

REST Adapter in SAP PI

Create Operation Mapping

Two Operation mapping will be created

  1. For Add Operation

REST Adapter in SAP PI

2. For Subtraction Operation

REST Adapter in SAP PI

 

Configuration Steps

In this section, all configuration steps will be shown.

  1. Create Sender REST Adapter
  2. Create Receiver SOAP Adapter
  3. Create ICO

Let’s start with REST Adapter which is most important in this scenario

Create REST Adapter

General tab: Select the format of the file JSON or XML.

I will be using the JSON format for request and response.

REST Adapter

Channel Selection – Here define the endpoint.

As it is a calculator service, I am defining Calc.

API URL will look like — http://<hostname:port>/RESTAdapter/calc

REST Adapter

REST Resource:

Third tab; “REST Resources”, within the URL Pattern option, select “Custom Pattern” and put a forward slash “/” as the pattern.

Also, select the XI Dynamic Attribute “REST Service (service)”, here provide the value for your “HTTP Header Element” that would be passed from the consumer application

REST Adapter in SAP PI

REST Operation:

Select Value Source as HTTP Operation.

REST Adapter in SAP PI

Operation Determination:

Here the Sender REST Adapter maps the incoming message with the appropriate service interface operation.

  • Variable – Enter {service}
  • Expression – This is a value passed by the consumer to determine which operation to be called, e.q. – Add
  • Operation – provide the exact name of “Request Message” as well as the corresponding namespace in the Namespace column.
  • QoS: The quality of service for each operation

REST Adapter in SAP PI

Create Receiver SOAP adapter

Here specify different actions add and sub based on WSDL.

Two channels will be created

SOAP Channel in SAP PI

Add Action

SOAP Channel - Add

Create the ICO

REST Adapter in SAP PI

Receiver Tab:

This is an important configuration select the Operation Specific.

REST Adapter in SAP PI

Receiver Interface Tab:

Select the mapping for different operations

REST Adapter in SAP PI

All configurations steps are complete now.

Testing

Any REST client can be used here for sending the request to SAP PI.

Testing for add operation:

Payload used

{
“Num1”: “2”,
“Num2”: “1”
}

In Header pass the operation as Add

REST Adapter in SAP PI

 

Now with the same payload change the operation as Sub

REST Adapter in SAP PI

Check out more blogs on REST Adapter

Sync Scenario using REST adapter in SAP PI

REST Adapter scenario in SAP PI – JSON/XML

Async Scenario using REST Adapter Scenario in SAP PI

Error Handling in REST Adapter – SAP PI

SAP reference Sender REST Adapter

2 thoughts to “REST Adapter with Multiple Operations in SAP PI”

  1. Hi! I’ve just wanted to say that you saved my day! Thank you for this useful and detailed explanation!

    1. Thank you so much, Adrian, for your kind words… we’re glad our blog was helpful to you.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.