Share your advanced knowledge/code with the community.
Stefan Schnell
 
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am

How To Use Apache Olingo OData Client with SpiderBasic

by Stefan Schnell Tue Dec 26, 2017 11:15 am

Hello community,

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-------------------------------------------------------------------


Image

Enjoy it.

Cheers
Stefan
Last edited by Stefan Schnell on Tue Dec 26, 2017 5:40 pm, edited 1 time in total.
User avatar
Peter
 
Posts: 447
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: How To Use Apache Olingo OData Client with SpiderBasic

by Peter Tue Dec 26, 2017 11:51 am

Interesting... Thanks! Image

Greetings ... Peter
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 1 guest