Creating a call to a REST API to load a JSON model to bind to the view/controller. Creating a freestyle Fiori App using the Managed App Router
- In oninit function within the view controller, try to load a JSON Model to bind to view
e.g. (new JSONModel()).loadData("/Products"); NB: Full URL is = https://dummyjson.com/Products)
xs-app.json Entry as follows { "source": "^/Products", "destination": "APITEST", "authenticationType": "xsuaa", "csrfProtection": false },
APITEST Destination in BTP configured with no authentication and URL = https://dummyjson.com/
The HTML5 app is deployed to BTP Cloud Foundry
Get a 404 error when clicking on the app from the BTP Cockpit HTML5 app list. However if I change step 1 to remove the prefix /Products to Products it resolves correctly. e.g.
(new JSONModel()).loadData("Products") is good. But to further complicate matters, when I then deploy the app to the Build App launchpad, it stops working ! NB. I have tried both variations with the launchpad and it doesn't work either with the leading / or without.
Any pointers on how I may have configured the files incorrectly to get this to resolve.
In the case (without a launchpad) and using "Products" in the relative URL, the resolved URL when I look in the 'Network' via Developer Tools in Chrome includes the application name as part of the URL to access via the Destination Service
Realised that you need to prefix the URL correctly when calling the loadData() method on the JSON model using the following utility
sap.ui.require.toUrl(appPath+"/Products").
var appId = this.getOwnerComponent().getManifestEntry(“/sap.app/id”); var appPath = appId.replaceAll(“.”, “/”);
Taken from the following blog but using sap.ui.require.toUrl as getModulePath is now deprecated.
https://blogs.sap.com/2020/09/08/calling-external-api-in-custom-task-ui-of-workflow-in-cloud-foundry/