Consume a REST API in an MDK App
- How to create a mobile project in SAP Build Lobby
- How to configure a Mobile Services application in SAP Business Application Studio via Storyboard
- How to configure a REST endpoint as a destination in Mobile Services application
- How to create a MDK Service file pointing to REST endpoint destination
- How to use
RestService SendRequestAction to make directly call toPetstoreAPI
Prerequisites
- Tutorial: Set Up Business Application Studio for Mobile Technologies
- Install SAP Mobile Services Client on your Android device or iOS

Android
iOS
(If you are connecting toAliCloudaccounts, you will need to brand your custom MDK client by allowing custom domains.)
You may clone an existing metadata project from the MDK Tutorial GitHub repository and start directly with step 15 in this tutorial but make sure you complete step 2&3.
Mobile Development Kit allows you to consume REST APIs. You need to first define REST endpoint as a destination and then easily bind a RestServiceTarget to an MDK control e.g., ObjectTable, ContactCell, ObjectCollection etc. This assumes the REST service returns JSON similar to how OData requests are returned.
A publicly available Petstore API from swagger.io is used as an example in this tutorial.

- Step 1
-
Open
Swagger Petstore, find all pets with status asavailable.
-
Click Execute to get the response.

By looking at results, you now have understood
- what is the Request URL to retrieve pet information
- what is header parameter to be passed in GET call
- what is the response code
- how the response body looks like
-
- Step 2
This step includes creating a mobile project in SAP Build Lobby.
-
In the SAP Build Lobby, click Create > Create to start the creation process.

-
Click the Application tile and choose Next.

-
Select the Mobile category and choose Next.

-
Select the Mobile Application to develop your mobile project in SAP Business Application Studio and choose Next.

-
Enter the project name
mdk_petstore(used for this tutorial) , add a description (optional), and click Review.
SAP Build recommends the dev space it deems most suitable, and it will automatically create a new one for you if you don’t already have one. If you have other dev spaces of the Mobile Application type, you can select between them. If you want to create a different dev space, go to the Dev Space Manager. See Working in the Dev Space Manager.
-
Review the inputs under the Summary tab. If everything looks correct, click Create to proceed with creating your project.

-
Your project is being created in the Project table of the lobby. The creation of the project may take a few moments. After the project has been created successfully, click the project to open it.

-
The project opens in SAP Business Application Studio.

When you open the SAP Business Application Studio for the first time, a consent window may appear asking for permission to track your usage. Please review and provide your consent accordingly before proceeding.

-
- Step 3
The Storyboard provides a graphical view of the application’s runtime resources, external resources, UI of the application, and the connections between them. This allows for a quick understanding of the application’s structure and components.
- Runtime Resources: In the Runtime Resources section, you can see the mobile services application and mobile destination used in the project, with a dotted-line connected to the External Resources.
- External Resources: In the External Resources section, you can see the external services used in the project, with a dotted-line connection to the Runtime Resource or the UI app.
- UI Application: In the UI Applications section, you can see the mobile applications.
-
Click on the + button in the Runtime Resources column to add a mobile services app to your project.

This screen will only show up when your CF login session has expired. Use either
CredentialsORSSO Passcodeoption for authentication. After successful signed in to Cloud Foundry, select your Cloud Foundry Organization and Space where you have set up the initial configuration for your MDK app and click Apply.
-
Click on the + button to add a new mobile services app configuration.

-
In the Basic Information step, provide the required information and click Next.
Field Value Application NameSAP MDK REST APIApplication IDmyapp.mdk.restapiSecurity SettingsLeave the default value as XSUAA
-
In the Destinations step, provide the required information and click Create App.
Field Value Destination Nameswagger_petstoreDestination TypeInternet DestinationURLhttps://petstore.swagger.io/v2SSO MechanismNo Authentication
-
Mobile Services App may take 2-3 minutes in creating the required configuration. You will notice the app state as
Creating.
-
Once the app is in
Createdstate, click Add App to Project.
You can access the mobile services admin UI by clicking on the Mobile Services option on the right hand side.
In the storyboard window, the app will be added under the Runtime Resources column.

-
Click the + button in the UI application column header to add mobile UI for your project.

-
In the Basic Information step, select No for the Enable Auto-Deployment to Mobile Services After Project Creation property, and click Finish. You will modify the generated project in next step and will deploy it later.

-
After clicking Finish, the storyboard is updated displaying the UI component. The MDK project is generated in the project explorer based on your selections.

- Step 4
-
Right-click the Services folder | MDK: New Service.

-
Provide the below information and click Finish.
Field Value NamepetstoreData SourceSelect Mobile Servicesfrom the dropdown. You will be asked to select the Mobile services landscape where you have configured the MDK appDestinationSelect swagger_petstorefrom the dropdownPath SuffixLeave it as it is Language URL ParamLeave it as it is REST Servicechoose this option 
.serviceand.xml(empty file) have been created under the Services folder.
-
- Step 5
You will add an Object Table control item on
Main.pageto display the list of Pets.-
In the Layout Editor, expand the Controls | Data Bound Container group, drag and drop the Object Table control onto the
Main.pagearea.
-
Provide the required information for Target section:
Field Value TargetSelect REST Service Targetfrom the dropdownServiceSelect petstore.servicefrom the dropdownPathEnter /pet/findByStatus?status=available
You can find more details on Target in documentation.
Method GET is pre-selected for binding the
ObjectTablecontrol to aRestServiceTarget. -
Under Appearance, provide below information:
Property Value Descriptionleave it empty Footnoteleave it empty PreserveIconStackSpacingSelect falsefrom the dropdownProgessIndicatorleave it empty Status{status}SubheadPet Name: {name}Substatusleave it empty TagsClick the item0and click the trash icon to delete the default itemTitlePet ID: {id}
-
In the Avatar Grid section of the Properties pane, remove the default Avatar. First, click on the
item0, a trash icon appears. Click on the trash icon to delete the default item.
-
In the Avatar Stack section of the Property pane, remove the default Avatar. First, click on the
item0, a trash icon appears. Click on the trash icon to delete the default item.
If you see any error in Main.page (code editor), ignore it as MDK editor currently can’t validate such REST Service endpoint properties.
-
- Step 6
So far, you have learned how to build an MDK application in the SAP Business Application Studio editor. Now, you will Deploy the Project definitions to Mobile Services to use in the Mobile client.
-
Click the Deploy option in the editor’s header area, and then choose the deployment target as Mobile Services .

-
Select deploy target as Mobile Services.

If you want to enable source for debugging the deployed bundle, then choose Yes.

You should see Deploy to Mobile Services successfully! message.

-
- Step 7
SAP Business Application Studio includes a feature that displays a QR code for onboarding in the mobile client. To view the onboarding QR code, click the Application QR Code icon in the editor’s header area.

The On-boarding QR code is now displayed.

Leave the Onboarding dialog box open for the next step.
- Step 8
Congratulations, you have learned how to consume a REST API in MDK app to display Pets list.
Next, you will learn how to create a new pet record.
- Step 9
-
In
Swagger Petstore, add a new pet to the store.
There is payload example to be passed for adding a new pet.
-
For testing, use below payload.
JSONCopy{ "name": "pet-test", "status": "available" } -
Click Execute to get the response.

By looking at results, you now have understood
- what is the Request URL & body to create a new pet record
- what are header parameters to be passed in POST call
- what is the response code
- how the response body looks like
With above details, you will now create a new MDK rule to create a new Pet record.
-
- Step 10
In this step, you will create a Section page with a Form Cell Section to contain the Form Cell controls. You will add the fields that will be editable by the end-user.
-
Right-click the Pages folder | MDK: New Page | Section | Next.

-
In the Base Information step, enter the Page Name as
Pet_Createand click Finish.
-
In the Properties pane, set the Caption to Create Pet.

-
Now, you will add the fields (Pet name and Status) for creating a new pet record by the end-user. In the Layout Editor, expand the Static Container group. Drag and drop Form Cell section onto the Page area.

Form Cell section is used to contain Form Cell controls in a section page.
-
You will now add Form Cell controls in the Form Cell Section. Expand the Form Cell Controls group, drag and drop a Simple Property onto the Page area.

-
Drag and drop one more Simple Property control onto the page so you have two total controls.

-
Select the first Simple Property control and provide the below information:
Property Value NameFCCreatePetCaptionPet NamePlaceHolderEnter Value
-
Select the second Simple Property control and provide the below information:
Property Value NameFCCreateStatusCaptionStatusPlaceHolderEnter Value
-
- Step 11
After filling-up the details for creating a new pet record, you will send these data to the backend.
-
In
Pet_Create.page, drag & drop an action bar item to the right corner of the action bar.
-
In the Properties pane, click the link icon to open the object browser for the System Item property. Double click the Save type and click OK.

-
Navigate to Events tab, click three dots icon and click
create a new rule/action.
-
Keep the default selection for Object Type (as Action) and Folder path.

-
Choose
REST Servicein Category | selectREST Service Send RequestAction | Next.
-
In the Base Information, provide the below information:
Field Value NameCreatePetServicechoose petstore.servicefrom the dropdownPath/pet
-
For
RequestPropertiesobject, choosePOSTmethod from the dropdown. UnderBody, switch toobject typeby clicking the icon, once it’s color has changed, click onBody[0]to add array items, this should now display a create icon in front ofBody[0]. Click Create icon to create an array item(0).Provide the below information:
Field Value KeynameValueBind it to input control #Control:FCCreatePet/#Value
-
Click create icon to add another array item(1).
Field Value KeystatusValueBind it to input control #Control:FCCreateStatus/#Value
-
Set
FetchCSRFto false as you don’t need to obtain aCSRFtoken for thepetstoreservice, and click Finish.You can find more details about
SendRequestaction in help documentation. -
When the
CreatePet.actionis successful, you may want to close the page. Expand the Common Action Properties and bind the Success Action to theCloseModalPage_Complete.action.
What options are there in the RequestProperties object part of RestService SendRequest action?
-
- Step 12
Now, you will add a button on the
Pet_Create.pageand set it’sonPresstoClosePage.action.-
Drag and drop an Action Bar Item to the left corner of the action bar.

-
In the Properties pane, click the link icon to open the object browser for the System Item property. Double click the Cancel type and click OK.

System Item are predefined system-supplied icon or text. Overwrites Text and Icon if specified.
-
Now, you will set the
onPressevent toClosePage.action.In Events tab, click the dotted icon for the
OnPressproperty to open the Object Browser.Double click the
ClosePage.actionand click OK to set it as theOnPressAction.
-
- Step 13
You will add a button to the
Main.pagecalled Add. When you click on this button, you want to navigate to the create pet page.-
In
Main.page, drag and drop an Action Bar Item to the upper right of the action bar. -
Click the link icon to open the object browser for the
SystemItemproperty.Double click the Add type and click OK.

-
Navigate to the Events tab, click the dotted icon for the
OnPressproperty to open the Object Browser.
-
Keep the default selection for Object Type (as Action) and Folder path.

-
Choose UI in Category | click Navigation | Next.
-
In the Base Information, provide the below information and click Finish.
Property Value NameNavToPet_CreatePageToOpenSelect Pet_Create.pagefrom the dropdownModalPageSelect truefrom the dropdown
What is the _Type value for CreatePet.action?(Hint: Open CreatePet.action in Text editor)
-
- Step 14
Click the Deploy option in the editor’s header area, and then choose the deployment target as Mobile Services

- Step 15
You have created a new record consuming REST API. Similarly, you can also modify and delete an existing record.
- Understand the Petstore API to retrieve data
- Create a New Project Using SAP Build
- Configure the Project Using Storyboard
- Create a new MDK Service file
- Display Pets list in MDK page
- Deploy the Project
- Display the QR code for onboarding the Mobile app
- Run the Project
- Understand the Petstore API to create new record
- Create new page for new pet record
- Send data to the Backend
- Add cancel button on create pet page
- Navigate to create a new Pet Record
- Redeploy the Project
- Update the app