cancel
Showing results for 
Search instead for 
Did you mean: 

Consume Rest Service API with SAP Cloud SDK for iOS Application (SAP iOS SDK)

jyoti4567
Explorer

I have REST service APIs of Python/Java. I want to configure the same in SAP Cloud SDK and create application for iOS platform.

I followed below link, but its configuration details are for old SAP cloud structure.

https://blogs.sap.com/2019/03/25/step-by-step-consume-rest-service-api-with-sap-s4hana-cloud-sdk/

If any one can help me in configuring REST API service with new SAP cloud cockpit structure and also explain the steps to consume the same in iOS Application.

As per my analysis with REST API we don't have any metadata service, so iOS Assistance wont be able to create iOS Application for the same. So it would be helpful if any one can explain how to consume the cloud configured REST API in iOS Application for Authentication as well as fetching data.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member190800
Contributor

Hi Jyotishree,

For writing an iOS app with SAP Cloud Platform Mobile Services with REST services (non-OData), you are correct that without a metadata file, the Assistant app will not be able to generate the project with the onboarding template (which includes the authentication that you want).

You could learn about authentication with SAP Cloud Platform SDK for iOS in the SAPFoundation framework documentation. But, the easiest way to get this working is probably the following:

  1. Create the application definition directly in SAP Cloud Platform Mobile Services cockpit, rather than from the Assistant. Add a Destination for your REST service.
  2. Add the 'Sample Service' feature to the application (assuming you are in Cloud Foundry). This adds a 2nd destination, with an OData backend. Alternatively, you could add a 3rd party dummy service https://services.odata.org/V2/Northwind/Northwind.svc/.
  3. In the Assistant, generate the new Xcode project following the 'Reuse Existing App' flow. Use the 'Onboarding' template, rather than Master-Detail.
  4. Delete the folder named 'Proxy Classes' in the generated Xcode project.

This will give you the app template with the onboarding & authentication pre-implemented. You can then reference your REST Service using the sapURLSession instance from the onboardingContext.

jyoti4567
Explorer
0 Kudos

Hi Stan,

I followed your step and created an application. Please find below screen shot for reference.

But as per your suggestion how to reference REST Service using the sapURLSession instance to the onboardingContext, as by default its taking authorisation information from ConfigurationProvider.plist and also use oData destination value(That we need to delete, as its a dummy URL) for authentication process.

Also in cockpit destination, I have configured REST service base URL. In iOS application for respective URLs we need to add parameters to fetch data.

Please help in below queries.

1) How to reference REST Service using the sapURLSession instance to the onboardingContext, as its taking destination ID information for oData service, So If I remove proxy classes and OData Url, then how to authenticate the app as well as how to fetch data?

2) How to fetch base URL of REST service through cloud?

3) How to data respective URL's parameter to base service for cloud?

Thanks,

Jyotishree

0 Kudos

Hi Jyotishree,

If you want to use the SAP Cloud SDK (for Java) to create a domain model for a REST service, then you need an OpenAPI specification file. If you do not have that file, then please ask the service maintainer to provide the file.

If the maintainer is not providing you the specification file, then you have the following options:

  • Define your own specification file and generate a domain model with Cloud SDK. Then you need to maintain it yourself. Functional correctness must be managed by yourself.
  • Don't use an extensive domain model from Cloud SDK and instead try to access the data with hardcoded code by yourself. You may still use Cloud SDK for managing connectivity.

Please note:

Opposed to REST services, an OData service would require an EDMX / metadata file.

Best regards

Alexander

jyoti4567
Explorer
0 Kudos

Hi Alexander,

As OData works, I wanted to implement REST service in the same way. I wanted to integrate REST API Base service in cloud. Then authenticate my application and using cloud proxy url will add extra parameters to the base service to fetch Data for different controllers.

We want to move our existing application(using REST API) to SAP cloud. We cant change APIs to oData here. So we are looking some way to integrate REST API in cloud.

As per your point to use OpenAPI specification file, we dont have this file. So for other options if you can explain it in details that would be helpful.

former_member186608
Active Participant
0 Kudos

Hi Jyotishree,

I can hardly get the full picture of what you want to achieve.

Can you please outline the exact sequence of one example call from your iOS application to the target system and also explain which role SAP Cloud and the SAP Cloud SDK play?

What confuses me most is that you referring to a blog that aims to generate Java classes for a REST API but as far as I know iOS apps are written in Swift.

So as you see, it helps when you elaborate more clearly and specifically of what you want to achieve and, most importantly, which concrete problems you face or questions you have.

In addition, I recommend you double-check with the REST API owner again as I think that an OAS file can definitely make your life as service consumer much easier.

jyoti4567
Explorer
0 Kudos

Hi Marco,

I am referring Java tutorial just to understand the process to fetch REST API. But I am creating iOS application here.

My requirement here is I want to fetch REST API in my iOS Application instead of OData API using SAP Cloud Platform.

If you refer https://developers.sap.com/tutorials/fiori-ios-scpms-create-sample-app.html, here we are using OData API Base URL in mobile connectivity feature to create metadata and the same is used in our iOS Application to create proxy classes and to fetch data. (Screenshot attached for reference)

But here my requirement is I want to access REST API Instead of OData API like http://dummy.restapiexample.com/api/v1/employees in my iOS Application using SAP cloud.

Kindly help me and explain me the steps for the same.

former_member186608
Active Participant
0 Kudos

Understood, I am requesting tag removal for "SAP Cloud SDK" then as I see no relationship to your question.