Reputation: 99
In my SAPUI5 application , we are trying to get the data from REST service. I created the destination in SCP cockpit and mentioned the same destination in neo-app.json file. I am successfully able to get the data via AJAX call. My question is : Is this the only way to get the data from REST service. Because for Northwind service I have not used any AJAX call. I simply mentioned my destination name in the neo-app.json file , created a datasource in my manifest.json and using the datasource I created a model. But I can not do the same for my REST Service. While creating the data source I am getting 500 Internal Server Error.
Thanks & Regards, MS
Upvotes: 0
Views: 1925
Reputation: 3994
The Northwind service is an oData service which adheres to the Open data protocol. So you can create a datasource which can be used to create an oData model within UI5. UI5 internally uses data.js which provides convenient methods to perform service requests like read, update, insert or delete so you don't have to perform any AJAX calls and keep manipulating URL's. Your bindings and aggregations are also automatically managed by UI5 when you use any of the UI5 data models(oData/JSON/XML/ResourceModel).
If your JAVA based service implements the oData protocol, you could use it similar to the Northwind service. If it provides response as JSON or XML, you could use the JSON Model or the XML model. However if the response is in some other format, you will have to use AJAX calls, parse the data & convert it preferably to JSON. You could then use it with a JSON Model.
You will have to add the destination in your neo-app.json
{
"path": "/comments",
"target": {
"type": "destination",
"name": "JAVAJSON",
"entryPath": "/comments"
},
"description": "JAVA based REST API"
}
Then create a model in your manifest.json
"models": {
"":{
...
...
}
"DataModel": {
"type": "sap.ui.model.json.JSONModel",
"settings": {},
"uri": "/comments",
"preload": false
}
}
Upvotes: 2