Create a Genero BDL client for a JSON Web service

Web services generated using the BAM provide an API that you can use to write your Genero BDL Web service client.

When a JSON Web service (WebServiceJSON) is generated, an API is created for your use. BAM names the API by appending "_serviceclient" to the end of the Web service name:
  • WebService_serviceclient.4gl
This API provides the methods needed to create a JSON Web service client. Use the methods provided in the API to ask for CRUD operations from the JSON Web service. It must be provided by the Web service producer.
Tip: An example of the server client API usage is provided in the OfficeStore demo; examine the JSONClient.4gl file found in the node named JSONClient.

Import the libraries

In your Web services client application, use an IMPORT statement to include the API, as well as the common library libdbappWSClient, as shown in this example:
IMPORT FGL libdbappWSClient
IMPORT FGL JSONSuppliers_serviceclient

The common library provides functions necessary for setting the URL to the Web service server.

Provide the URL for the Web service

The only URL you need to provide is the URL to the Web service server itself, as shown in this example:
CALL libdbappWSClient.setUrlServer("http://localhost:6394/ws/r/JSONServer")
The format of the URL:

http://<server>/<alias>/ws/r/<group>

where:
  • <server> - Service server name or IP address.
  • <alias> - fastcgi / http dispatcher configuration
  • <group> - Web service server, for example, GAS group configuration or external configuration file name

Understanding the methods

For this example, start with this example of a Customers Web service, containing three records: Accounts, Orders, and LineItems. The Accounts record is the master.
Note: The Customers web service example used for these topics can be found under the Four Js Genero github repository. See http://github.com/FourjsGenero/ex_bam_json_web_service

Figure: Customers Web Service example


screenshot of master-detail relationships between records for a Customers Web Service entity
From this example, you can see that you have methods that affect the whole document, the Accounts, the Orders, and the LineItems, as shown in this table below:
Table 1. Client API functions
Function suffix Description
_createAll() Creates a collection of documents.
_readAll() Reads a collection of documents from a Query by Example (QBE).
_Accounts_create() Creates a collection of new accounts.
_Accounts_readRow() Reads the account specified by accountID.
_Accounts_update() Updates a collection of accounts
_Accounts_updateRow() Updates the account specified by accountID.
_Accounts_delete() Deletes a collection of accounts
_Accounts_deleteRow() Deletes the account specified by accountID.
_Orders_create() Creates a collection of new orders.
_Orders_readRow() Reads the order specified by orderID.
_Orders_update() Updates a collection of orders
_Orders_updateRow() Updates the order specified by orderID.
_Orders_delete() Deletes a collection of orders
_Orders_deleteRow() Deletes the line item specified by lineItemID.
_LineItems_create() Creates a collection of new line items.
_LineItems_readRow() Reads the line item specified by lineItemID.
_LineItems_update() Updates a collection of line items
_LineItems_updateRow() Updates the line item specified by lineItemID.
_LineItems_delete() Deletes a collection of line items
_LineItems_deleteRow() Deletes the line item specified by lineItemID.