Compressing and extracting data

Example 1 (using HTTPClient)

The HTTPClient object sends a request with a header "Accept-Encoding:gzip" which informs the RESTFul Web service that the client can extract data; then the Web service returns a compressed package and a response header "Content-Encoding: gzip" which indicates that the data is compressed.

HttpClient   lhc_Client

String     ls_Url, ls_Method, ls_Body, ls_Respose
Long       ll_rtn
Blob       lb_body

lhc_Client = Create HttpClient

ls_Url = "https://demo.appeon.com/pb/webapi_client/department"
ls_Method = "GET"
lhc_Client.timeout = 10
lhc_Client.SetRequestHeader ( "Content-Type", "application/json" )
//Sets the auto-decompression request header to gzip
lhc_Client.SetRequestHeader("Accept-Encoding", "gzip")
ll_rtn = lhc_Client.sendrequest( ls_Method, ls_Url )

If ll_rtn = 1 Then
//Gets the response header
  ls_Respose = lhc_Client.Getresponseheaders( )
  messagebox("Responseheaders",ls_Respose)
//Gets the response body
ll_rtn = lhc_Client.GetResponsebody( ls_Body,EncodingUTF8!)
MessageBox ( "Responsebody", ls_Body )

Else
  MessageBox ( "SendRequest Failed", "Return:" + String ( ll_rtn ) )
End If

If IsValid (lhc_Client) Then Destroy ( lhc_Client )

Example 2 (using RESTClient)

The RESTClient object sends a request with a header "Accept-Encoding:gzip" which informs the RESTFul Web service that the client can extract data; then the Web service returns a compressed package and a response header "Content-Encoding: gzip" which indicates that the data is compressed; and then the RESTClient object retrieves data from the compressed package.

RestClient   lrc_Client
String     ls_Url, ls_Method
Long     ll_rtn

lrc_Client = Create RestClient
ls_Url = "https://demo.appeon.com/pb/webapi_client/department"
ls_Method = "GET"
lrc_Client.SetRequestHeader ("Content-Type", "application/json")
lrc_Client.SetRequestHeader("Accept-Encoding", "gzip")

ll_rtn = lrc_Client.Retrieve( dw_1,ls_Url )
If ll_rtn >= 0 And lrc_Client.GetResponseStatusCode() = 200 Then
  MessageBox( "Retrieve Success","Rows:" + String ( ll_rtn ))
Else
  MessageBox( "Retrieve Failed","Rows:" + String ( ll_rtn ))
End If

If IsValid (lrc_Client) Then Destroy ( lrc_Client )

Example 3 (using OAuthClient)

The OAuthClient object sends a request with a header "Accept-Encoding:gzip" which informs the RESTFul Web service that the client can extract data; then the Web service returns a compressed package and a response header "Content-Encoding: gzip" which indicates that the data is compressed.

OAuthRequest   loa_Request
OAuthClient loa_Client

ResourceResponse   lrr_Response
Integer     li_rtn
Long       ll_rtn
String     ls_Body,ls_Response,ls_Token

loa_Client = Create OAuthClient

ls_Token = "eyJhbGciOiJSUz......"
//Sets the auto-decompression request header to gzip
loa_Request.SetHeader("Accept-Encoding", "gzip")
li_rtn = loa_Request.SetAccessToken (ls_Token)
loa_Request.Method = "GET"
loa_Request.Url = "https://demo.appeon.com/pb/webapi_client/identity/departments"
li_rtn =loa_Client.RequestResource( loa_Request, lrr_Response )
If li_rtn = 1 Then
   //Gets the response header
    ls_Response = lrr_Response.getheaders( )
messagebox("Responseheaders",ls_Response)
//Gets the response body
    ll_rtn = lrr_Response.getbody( ls_Body)
   MessageBox( "Body", ls_Body )
                
Else
  MessageBox ( "RequestResource Failed","RequestResource Return:" + String ( li_Rtn ) )
End If

If IsValid ( loa_Client ) Then Destroy ( loa_Client )