more and more moves OData into the focus of web applications. At the moment is OData one of the most interesting interface technologies in the context of SAP. To use it offers SAP for this the UI5 framework. But with fantastic SpiderBasic you can use this interfaces easily too.
Here an example how to use Northwind web service via Apache Olingo with SpiderBasic. In this example I read some data from Products collection.
Code: Select all
; Begin-----------------------------------------------------------------
; Directives----------------------------------------------------------
EnableExplicit
; Constants-----------------------------------------------------------
Enumeration
#MainWin
#Editor
#btnGetData
EndEnumeration
; Sub successCallback-------------------------------------------------
Procedure success(tabledata, response)
Protected tmp.s, size.i, i.i
Protected product_id.s, product_name.s
!v_tmp = v_response.statusCode;
If tmp <> "200"
ProcedureReturn
EndIf
!v_size = v_tabledata.value.length;
Dim arr(size)
!a_arr = v_tabledata.value;
For i = 0 To size - 1
!v_product_id = a_arr[v_i].ProductID;
!v_product_name = a_arr[v_i].ProductName;
Debug product_id + " " + product_name
Next
EndProcedure
; Sub errorCallback---------------------------------------------------
Procedure error()
Debug "An Error Occured"
EndProcedure
; Sub GetData---------------------------------------------------------
Procedure btnGetData()
Protected uri.s
uri = "http://services.odata.org/V3/Northwind/Northwind.svc/Products"
!var v_headers = { "Content-Type": "application/json", Accept: "application/json" };
!var v_request = {
! method: "GET",
! requestUri: v_uri,
! headers : v_headers,
! Data: null,
! enableJsonpCallback: true
!};
!odatajs.oData.request(v_request, f_success, f_error);
EndProcedure
; Sub Main------------------------------------------------------------
Procedure Main()
If OpenWindow(#MainWin, 100, 100, 640, 480,
"OData with Olingo JavaScript Library")
EditorGadget(#Editor, 10, 10, 620, 418)
SetGadgetText(#Editor,"Olingo JavaScript Library" + #CRLF$ +
"Get data from Northwind service")
ButtonGadget(#btnGetData, 10, 438, 190, 32, "Get Data")
BindGadgetEvent(#btnGetData, @btnGetData())
EndIf
EndProcedure
; Sub LoadScript------------------------------------------------------
Procedure LoadScript(script.s, *func)
!$.getScript(v_script, p_func);
EndProcedure
; Main----------------------------------------------------------------
LoadScript("odatajs-4.0.0.js", @Main())
; End-------------------------------------------------------------------
Enjoy it.
Cheers
Stefan