What is Rest Web service?
REST stands for
Representational State Transfer, which is kind of easiest way to communicate with external systems in Cloud Solution. It is an architectural style for designing networked applications.
REST services provide a uniform interface using standard HTTP operations (such as GET, POST, PUT...) and exchange representations of resources. JSON and XML are frequently used formats in REST services.
So, I would like to document it here and let you know the same so that it will stay as a reference to everyone.
Tenant: SAP Business ByDesign.
Example: Weather Report (with Params).
Scenario: Integrate a simple weather API with SAP Cloud Solution.
Weather API: www.sankaranss.com/tutorial/rest/weather.php. For time being I created a sample API where it accepts one location parameter. I will keep this API open in case you want to try out. I used free resource for finding weather. So you can get only approximate weather while comparing with Google weather result.
Process Flow
- Create an External Web Service Using REST.
- Create A Communication Arrangement.
- Create A Custom Business Object.
- Create an action script.
Step 1: Create an External Web Service Using REST
- Login into the SDK. Select your solution from “My Solution” window.
- In the Solution Explorer, right-click your solution and select Add New Item.
The Add New Item dialog opens.
- Select SAP Service Integration External Web Service Integration and click Add.
The External Web Service Integration Wizard opens.
- In the Enter Web Service Name and Type step, enter a name for the Web service and select REST. Click Next.
- In the Enter End Point of REST Service step, do the following:
- In the Define Communication Scenario step, do the following:
- Select the Create Communication Scenario checkbox to create a communication scenario.
- Enter a name for the communication scenario. It must start with a capital letter and can have 25 characters (letters, digits, and underscores).
- Select the Allow Non-Secure URLs (HTTP) checkbox to allow non-secure communication.Click Next.
- On the Review page, review your entries and click Finish.
- In the Solution Explorer, an external Web service integration file WeatherReport01.wsid and a communication scenario definition file WeatherReport01.csd are displayed. Save and Activate both the files.
A communication scenario and a communication system (The communication system is created automatically) are generated in the SAP cloud solution. These can be used to create a communication arrangement.
Step 2: Create a Communication Arrangement
To test the communication scenario, you need to create a communication arrangement in the SAP cloud solution.
- In the studio, in the Solution Explorer, right-click the communication scenario definition (WeatherReport01.csd) file and click Manage Communication Arrangement.
- Log on to the SAP cloud solution.
The Communication Arrangements work center view opens.
- Click New.
- The New Communication Arrangement view opens.
- In the Select Scenario step, select the communication scenario WeatherReport01 which you have created in the studio and click Next.
- In the Define Business Data step, select the System Instance ID as “WeatherReport01” and click Next.
- In the Define Technical Data step, Click Edit Advance Settings Button do the following:
- Uncheck “Use Basic Setting”
- Application Protocol: Http
- Set Protocol as Hypertext Transfer Protocol(http).
- Host Name: www.sankaranss.com
- Port: 80
- Path: /tutorial/rest/weather.php
- Authentication Method: None
- Click Next.
- In the Review step, review your entries and click Check Completeness. Then click Finish and close.
To Test Rest web service
- Choose Communication Arrangement (WeatherReport01) -> Technical data -> Edit Advance Settings -> Check Connections. If you see a message as “Ping Successful”, your rest service is perfectly working.

- If you see any error message, first check your URL and port number.
- If you have done any modification in URL or in any other options, you have to click “Save and Reactive”, before clicking “Check Connection”.
Step 3: Create a Custom Business Object
Integrate the Weather Report with SAP Business ByDesign.
- Create a custom Business Object WeatherReport.
- Define elements as shown in the below screenshot.
- Save and Activate.
For more information about the Custom Business Object creation, see http://blog.sankaranss.com/2016/03/29/sap-byd-business-object/.
- Create screens for the WeatherReport BO and Design it.
For more information about the Screen creation and Design, see http://blog.sankaranss.com/2016/04/28/sap-byd-screen-types/.
Step 4: Create an Action Script
- Create getWeather Action script file for WeatherReport BO.
For more information about the Action and Events, see
http://blog.sankaranss.com/2016/04/11/sap-byd-actions-and-events/.
- Copy and paste below code.
import ABSL;
// Communication details
var ScenarioName = "WeatherReport01";
var ServiceName = "WeatherReport01";
var HttpMethod = "GET";
var HttpResource = "weather.php"; //URL - File Name
// not required for this example
var ContentType = "";
var Body = "";
var HeaderParameter : collectionof NameAndValue; // Set URL Parameter
var URLParameter : collectionof NameAndValue;
var URLParameterEntry : NameAndValue;
URLParameterEntry.Name = "location";
URLParameterEntry.Value = this.location;
URLParameter.Add(URLParameterEntry);
// Execute webservice call
var ws_result = WebServiceUtilities.ExecuteRESTService(ScenarioName, ServiceName, HttpMethod, HttpResource, URLParameter, HeaderParameter, ContentType, Body);
//Parse result of Web service and retrieve city name; you may have to adapt the logic to the Web service used
this.WeatherResult = ws_result.Content;
- Save and Active.
Finally, your files look as like below screenshot.
Step 5: Testing
- Log in as a business user.
- Navigate to the QA Screen by creating a custom BO instance.
- Enter the location. Ex. Bangalore,IN
- Click Get Weather
You can see Weather Report in Result area.
We have seen about integrate weather report with ByDesign using Rest Web service, and in the future article, we will learn more about it. Don’t forget to subscribe my blog and leave your comments to improve this article.
For more info. Please visit http://blog.sankaranss.com/2016/10/18/rest-webservice-sap-byd/