cancel
Showing results for 
Search instead for 
Did you mean: 

How to use REST API destination in SAP BTP and consume in UI5 application?

madhav15
Explorer
0 Kudos

Hello all,

I am developing UI5 application using SAP HANA Cloud Database and Spring boot API ( I deployed Spring boot app in Cloud foundry and deployed API working properly). I am getting issue while fetching API in UI5 application through ajax call. I am consuming API as a BTP Destination. following is my destination:

I am providing destination in xs-app.json:

I am calling API in ajax call. I have tried with absolute URL and relative URL both like /EmployeeDest/employees and EmployeeDest/employees, one is given in screen shot.

I am facing 404 issue while fetching API in UI5 application (without deploying):

And after UI5 app deployment I am getting 500 Error:

I have tried many solution and follow one blog, but nothing works.

Please guide me for issue.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

madhav15
Explorer
Hi  shubhmis,

Thanks for responding. My problem has been resolved now. I have changed in ui5.yaml as you said and do more changes. Like in ui5.yaml file I changed as follows:

 customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
ignoreCertError: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted
ui5:
path:
- /resources
- /test-resources
url: https://ui5.sap.com
backend:
- path: /employees
destination: EmployeeDest

I changed my in xs-app.json as follows:

{
"source": "^/(.*)$",
"target": "/$1",
"destination": "EmployeeDest",
"authenticationType":"none"
},

And My ajax call URL is:

url: appModulePath + "/employees",

Since I am using Managed Approuter, I need to use App module path (In case of Standalone Approuter we use Application ID). I got app module path using this code:

              var appId = this.getOwnerComponent().getManifestEntry("/sap.app/id");
var appPath = appId.replaceAll(".", "/");
var appModulePath = jQuery.sap.getModulePath(appPath);

My problem is resolved using this configurations.

Thanks.

nsathya_infy
Explorer
0 Kudos

Hi Madhav,

Do you have sample code for this in any repo? 

I'm trying to call a CAP Service, which is successful but I have another destination which is a REST APi which is failing.

Thanks, 

Sathya

Answers (3)

Answers (3)

Shubham_M
Participant

Hello,

It should be something like this to run it locally:

customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
ignoreCertError: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted
ui5:
path:
- /resources
- /test-resources
url: https://ui5.sap.com
backend:
- path: <patern for path>
destination: <your destination name>
madhav151
Explorer
0 Kudos

Hi shubhmis ,

Thanks for providing solution, but I have tried your solution and I am getting similar 400 Error which I mentioned earlier

Here is my code in ui5.yaml:

customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
ignoreCertError: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted
ui5:
path:
- /resources
- /test-resources
url: https://ui5.sap.com
backend:
- path: /employees
destination: EmployeeDest
Shubham_M
Participant

Hi,

For testing in BAS, in URL of Ajax call use /Employees as the path

When you deploy it to BTP launchpad you have to change the URL. You can refer step 4 of this blog on how to call using app module path.
Calling External API In Custom Task UI of Workflow in Cloud Foundry | SAP Blogs

Thanks,

Shubham

Shubham_M
Participant
0 Kudos

Hi,

For running locally in BAS, can you check the configuration in ui5.yaml file. In your local looks like you are passing a parameter test. Looking at your code it should have the below config there.

backend:
- path: /employees
destination: EmployeeDest

Also, generally, the content type is passed in the HTTP header than the data. Can you try removing that and running it on your server?
This is all assuming your destination URL is configured properly.

Thanks,

Shubham

madhav151
Explorer
0 Kudos

Hi shubhmis

Thanks for responding. I have changed content type from data to HTTP header. My BTP destination URL is configured properly (checked connection with 200 Status Code). This is my ui5.yaml configuration:

specVersion: "2.6"
metadata:
name: com.yash.samplecrudui
type: application
server:
customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
ignoreCertError: false
ui5:
path:
- /resources
- /test-resources
url: https://ui5.sap.com
- name: fiori-tools-appreload
afterMiddleware: compression
configuration:
port: 35729
path: webapp
delay: 300
- name: fiori-tools-preview
afterMiddleware: fiori-tools-appreload
configuration:
component: com.yash.samplecrudui
ui5Theme: sap_horizon
ui5.yaml file does not have backend configuration like as you said. Does I need to define that backend configuration in ui5.yaml? Because when I tried with backend config I was not able run my app, showing you can not define backend configuration here in ui5.yaml.

Please look into this.

Thanks.