User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

REST support was added to PowerBuilder in 2017 R2 and enhanced in 2017 R3.? PowerBuilder 2019 contains additional significant enhancements to REST support, including the following:

  • RetrieveOne method – For REST methods return one row
  • Submit method - sends request and returns data in one operation
  • SetRequestHeader behavior modified
  • GZIP compression handled automatically
  • Send[Method]Request, where method can be Get, Put, Post, Patch, Delete
  • Get and Set OAuth token methods
  • Get and set JWT token methods

?

?

RetrieveOne

  • Similar to the Retrieve method, but for calling services that only return one row
  • If the result set contains more than one row, only the first row is added to the DataWindow

client.RetrieveOne( dw_1, "https://jsonplaceholder.typicode.com/posts/1")

Submit

  • Sends data from a DataWindow, DataStore or JSONPackage object to a server.
  • It only uses the POST method
  • Primarily intended for sending updates from a DataWindow/DataStore to a SnapObjects based REST API
  • Syntax
    • objectname.Submit(string urlName, ref string response, DWControl dwObject{, boolean format})
    • objectname.Submit(string urlName, ref string response, DWControl dwObject {,DWBuffer dwbuffer}, boolean changedonly, boolean format)
    • objectname.Submit(string urlName, ref string response, DWControl dwObject, boolean primarydata, boolean filterdata, boolean deletedata, boolean dwcdata {, boolean format})
    • objectname.Submit(string urlName, ref string response, DWControl dwObject, DWBuffer dwbuffer{,long startrow{, long endrow{, long startcol{, long endcol}}}} {, boolean format})
    • objectname.Submit(string urlName, ref string response, ref JsonPackage package)
    • Where:
      • urlName – the url for the service
      • response – the data returned from the service
      • dwObject – DataWindow or DataObject
      • format - true for DataWindow JSON or ModelStore JSON, false for Plain JSON
      • dwBuffer – the DataWindow buffer to sent if you just want to send one buffer. Otherwise all are sent.
      • changed-only – whether to send just changed rows or all of them
      • primarydata, filterdata, deletedata, dwcdata - Boolean flags indicating whether that data should be sent
      • startrow, endrow, startcol, endcol – controls the range of data sent
      • package – the JSONPackage object to send data from

client.Submit("https://jsonplaceholder.typicode.com/posts", ls_response, dw_1, Primary!, 1, 1, false )

SetRequest Header

  • New optional replace argument
  • Syntax
    • client.SetRequestHeader ( string headerName, string headerValue, { Boolean replace } ):
      • TRUE – if the value already exists in the header, replace it
      • FALSE (default) – add the value even if it already exists in the header

GZip?

  • If the data is sent in gzip format, PowerBuilder automatically handles the decompression of the data
  • To enable, set the Accept-Encoding header to gzip on the request to the service
    • If the service supports it, the data will be sent back in gzip format
    • If not, the data will be sent back in JSON format

client.SetRequestheader( 'Accept-Encoding', 'gzip’, TRUE)

Statistics for a REST call without GZip compression: