OData Service

Consume an Odata service in sapui5 application (Read Odata service)


            How to consume an Odata service from sapui5 mobile application is explained here.
Pre-requisites
1.odata service
2.sapui5 library files loaded

      Here we will use OData Model of SAPUI5 framework.The OData model is a server-side model, meaning that the data set is only available on the server and the client only knows the currently visible (requested) data. Operations, such as sorting and filtering, are done on the server. The client sends a request to the server and shows the returned data.

     The OData model currently supports OData version 2.0.SAP reccommend using v2 model.

 Steps
  1. Create model instance.One OData model instance can cover only one OData service.
  2. var oModel = new sap.ui.model.odata.v2.ODataModel({
        serviceUrl: "https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/",
        /*headers: {
            "myHeader1" : "value1",
            "myHeader2" : "value2"
        }*/
    });
    
    
  3.  Read entity.This triggers a get request to the specified path.
  4. oModel.read("/Categories", {
        method: "GET",
        success: function(data) {
            alert(JSON.stringify(data));
        },
        error: function() {
    
        }
    });
    
  5. See Sample provided.Here on clicking the button OData read operation is performed.

  6. OData Read Operation
If you enjoyed this post, Please Share!!

5 comments :

Powered by Blogger.