Syntax
Description
Retrieves data to the DataWindow, DataWindowChild, or DataStore
from the RESTFul Web service. If the data received from the RESTful web
service is compressed as gzip, it will be automatically decompressed.
Only gzip compression format is supported at this moment. The developer
can use the SetRequestHeader function to set the Accept-Encoding header
to allow only the gzip compression format.
Applies to
RestClient object
Syntax
|
1 |
objectname.Retrieve ( dwControl, urlName {, data} {, tokenrequest} ) |
|
Argument |
Description |
|---|---|
|
objectname |
A reference to the RestClient |
|
dwControl |
The name of the DataWindow control, DataStore, or |
|
urlName |
A string whose value is the URL. |
|
data (optional) |
A string or blob data. If this argument is not |
|
tokenrequest (optional) |
A reference to the TokenRequest object for |
Usage
The JSON string returned from the RESTFul Web service APIs must be
in this format.
The RESTClient Retrieve function is not supported in
DataWindow/DataWindowChild/DataStore with the following presentation
styles: Composite, Crosstab, OLE 2.0, and RichText.
Although the RESTClient Retrieve function is not supported in the
Composite DataWindow, you can call GetChild function to get the child
DataWindow from the Composite DataWindow, and then call the Retrieve
function to retrieve the data into the child DataWindow.
Return value
Long.
Returns values as follows. If any argument’s value is null, the
method returns null.
>=0 — Returns the number of rows if it succeeds
-1 — General error
-2 — Invalid URL
-3 — Cannot connect to the Internet
-4 — Timed out
-5 — Get token error
-7 — Failed to decompress the response body
Example 1
This example retrieves data to a DataWindow:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
long ll_return RestClient lnv_RestClient lnv_RestClient = Create RestClient // Set DataObject dw_emp.DataObject = "d_sq_gr_emp" // Send request using GET ll_return = lnv_RestClient.Retrieve(dw_emp, "http://demo.appeon.com/PB/webapi_client/employee/102") // Check the return value if ll_return >= 0 then MessageBox("Success", "Rows = " + String(ll_return)) else MessageBox("Error", "Failed to retrieve data.") end if |
Example 2
This example retrieves data to a DataStore:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
long ll_return RestClient lnv_RestClient datastore lds_datastore lnv_RestClient = Create RestClient lds_datastore = create datastore // Set DataObject lds_datastore.DataObject = "d_sq_gr_emp" // Send request using GET ll_return = lnv_RestClient.Retrieve(lds_datastore, "http://demo.appeon.com/PB/webapi_client/employee/102") // Check the return value if ll_return >= 0 then MessageBox("Success", "Rows = " + String(ll_return)) else MessageBox("Error", "Failed to retrieve data.") end if |
Example 3
This example retrieves data to a DataWindowChild:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
int li_return RestClient lnv_restClient DataWindowChild ldwc_dept lnv_restClient = create RestClient //get the DataWindowChild dw_emp.getchild("dept_id", ldwc_dept) //Get data from web api using GET method li_return = lnv_restClient.retrieve(ldwc_dept, "https://192.0.3.177/appeon/api/v1/dept/list") if li_return >= 0 then messagebox("Success", "Rows = " + string(li_return)) else messagebox("Error", "Failed to retrieve data.") end if |
Example 4
This example passes the string data using POST method and
retrieves data to a DataWindow.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
long ll_return RestClient lnv_RestClient lnv_RestClient = Create RestClient String ls_json = '{"empId":100, "fname":" John", "lname": "Guevara"}' // Construct a POST request (supports all headers) lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") // Send the POST request (add data to the body and automatically set Content-Length header) ll_return = lnv_RestClient.Retrieve(dw_emp, "http://demo.appeon.com/PB/webapi_client/employee", ls_Json) // Check the return value if ll_return >= 0 then MessageBox("Success", "Rows = " + String(ll_return)) else MessageBox("Error", "Failed to retrieve data.") end if |
Example 5
This example passes the blob data using POST method and retrieves
data to a DataWindow.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Long ll_rc Blob lblb_data RestClient lnv_RestClient lnv_RestClient = Create RestClient // Set DataObject dw_1.DataObject = "d_employee" // Construct a POST request (supports all headers) lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") // Content-Length is set by Retrieve automatically // ... lblb_data = blob('{"empId":100, "fname":"John", "lname":"Guevara"}', EncodingUTF8!) // Send the POST request (add data to the body and automatically set Content-Length header) ll_rc = lnv_RestClient.Retrieve(dw_1, "http://demo.appeon.com/PB/webapi_client/employee/blob", lblb_data) // Check the return value if ll_rc >= 0 then MessageBox("Success", "Rows = " + String(ll_rc)) else MessageBox("Error", "Failed to retrieve data.") end if |
Example 6
This example passes the string data using POST method and
retrieves data to a DataStore.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
String ls_json Long ll_rc Datastore lds_1 RestClient lnv_RestClient lnv_RestClient = Create RestClient lds_1 = Create Datastore lds_1.DataObject = "d_employee" ls_json = '{"city": "Needham", "state": "MA", zipCode": "02192"}' // Construct a POST request (supports all headers) lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") // Content-Length is set by Retrieve automatically // ... // Send the POST request (add data to the body and automatically set Content-Length header) ll_rc = lnv_RestClient.Retrieve(lds_1, "http://demo.appeon.com/PB/webapi_client/employee", ls_Json) // Check the return value if ll_rc >= 0 then MessageBox("Success", "Rows = " + String(ll_rc)) else MessageBox("Error", "Failed to retrieve data.") end if |
Example 7
This example passes the blob data using POST method and retrieves
data to a DataStore.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Long ll_rc RestClient lnv_RestClient lnv_RestClient = Create RestClient blob lblb_data Datastore lds_1 lds_1 = Create Datastore // Set DataObject lds_1.DataObject = "d_employee" // Construct a POST request (supports all headers) lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") // Content-Length is set by Retrieve automatically // ... lblb_data = blob('{"empId":100, "fname":"John", "lname":"Guevara"}', EncodingUTF8!) // Send the POST request (add data to the body and automatically set Content-Length header) ll_rc = lnv_RestClient.Retrieve(lds_1, "http://demo.appeon.com/PB/webapi_client/employee/blob", lblb_data) // Check the return value if ll_rc >= 0 then MessageBox("Success", "Rows = " + String(ll_rc)) else MessageBox("Error", "Failed to retrieve data.") end if |
Example 8
This example passes the string data using POST method and
retrieves data to a DataWindowChild.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
int li_return string ls_data RestClient lnv_restClient DataWindowChild ldwc_dept lnv_restClient = create RestClient //Get DataWindowChild dw_emp.getchild("dept_id", ldwc_dept) ls_data = "{'did':1}" lnv_restClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") //Get data from web api using POST method li_return = lnv_restClient.retrieve(ldwc_dept, "https://192.0.3.177/appeon/api/v1/dept/findbyid", ls_data) if li_return >= 0 then messagebox("Success", "Rows = " + string(li_return)) else messagebox("Error", "Failed to retrieve data.") end if |
Example 9
This example passes the blob data using POST method and retrieves
data to a DataWindowChild.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
int li_return blob lblb_data RestClient lnv_restClient DataWindowChild ldwc_dept lnv_restClient = create RestClient lnv_restClient.setrequestheader("Content-Type", "Application/json;charset=utf-8") //Convert the string to a blob lblb_data = blob("{'did':1}", encodingutf8!) //Get DataWindowChild dw_emp.getchild("dept_id", ldwc_dept) //Pass data from web api using POST method li_return = lnv_restClient.retrieve(ldwc_dept, "https://192.0.3.177/appeon/api/v1/dept/findbyid", lblb_data) if li_return >= 0 then messagebox("Success", "Rows = " + string(li_return)) else messagebox("Error", "Failed to retrieve data.") end if |
Example 10
This example gets data from a Web site with token authentication
and then retrieves data to a DataWindow.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
integer li_return RestClient lnv_restClient TokenRequest lnv_tokenRequest lnv_restClient = create RestClient lnv_TokenRequest.tokenlocation = "http://192.0.3.177/oauth2/connect/token" //Location of the token lnv_TokenRequest.method = "post" //Request method lnv_TokenRequest.granttype = "client_credentials" //Grant type lnv_TokenRequest.clientid = "Af-Bf-ZPrD0j1aXrGRsnAgx2-rcuE-ZTQOr9mEvqsi" //client ID lnv_TokenRequest.clientsecret = "EH2OWHgxMgyKc-tN_EGZAh0Kg4-XS8AQi26vEJh" //client certificate li_return = lnv_restClient.retrieve(dw_dept, "https://192.0.3.177/appeon/api/dept", lnv_tokenRequest) if li_return >= 0 then messagebox("Success", "Rows " + string(li_return)) else messagebox("Error", "Failed to retrieve data.") end if |
Example 11
This example passes the blob data using POST method and retrieves
the data from the Web site with token authentication to the
DataWindow.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
integer li_return blob lblb_data RestClient lnv_restClient TokenRequest lnv_tokenRequest lnv_restClient = create RestClient lnv_TokenRequest.tokenlocation = "http://192.0.3.177/oauth2/connect/token" //Location of the token lnv_TokenRequest.method = "post" //Request method lnv_TokenRequest.granttype = "client_credentials" //Grant type lnv_TokenRequest.clientid = "Af-Bf-ZPrD0j1aXrGRsnAgx2-rcuE-ZTQOr9mEvqsi" //client ID lnv_TokenRequest.clientsecret = "EH2OWHgxMgyKc-tN_EGZAh0Kg4-XS8AQi26vEJh" //client certificate lnv_restClient.setrequestheader("Content-Type", "Application/json;charset=utf-8") lblb_data = blob("{'did':1}") li_return = lnv_restClient.retrieve(dw_dept, "https://192.0.3.177/appeon/api/dept", lblb_data, lnv_tokenRequest) if li_return >= 0 then messagebox("Success", "Rows " + string(li_return)) else messagebox("Error", "Failed to retrieve data.") end if |
Example 12
The client sends the server a request which includes the “gzip”
compression method; then the server compresses and returns the data as
requested; and then the client automatically extracts the data.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Integer li_Return RestClient lrc_Dept lrc_Dept = Create RestClient lrc_Dept.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") // Sets the compression method in the request header lrc_Dept.SetRequestHeader("Accept-Encoding","gzip") // DataWindow column name and type must match with those returned from // URL: https://demo.appeon.com/PB/webapi_client/department dw_submit.DataObject = 'd_example_dept' // dw_submit datawindow will display the return data li_Return = lrc_Dept.Retrieve(dw_submit,"https://demo.appeon.com/PB/webapi_client/department") If li_Return < 0 Then // Prints the error message End If |