Call the stub functions

Functions in the stub file allows you to write code in your own .4gl module that calls these functions as part of your client application.

The service information obtained from the REST Web Service provides information about using the service.

Using parameters and return values

To call a function in your client application, you must define variables for its input parameters and return values. These, for example, may be simple types or user-defined records.

Details for these variables can be obtained from the OpenAPI specification file (see Generate service description on demand ) or from the generated function in the stub file.

Record type defined in client stub


PUBLIC TYPE addUserRequestBodyType RECORD
    users_name STRING,
    users_address STRING,
    users_country STRING
    # ...
END RECORD

Calling a stub function in the client app

In this example the this variable is defined as a record type based on a user-defined record in the client stub, clientStub.addUserRequestBodyType.

Values are passed to the variable before calling the function.

Variables are defined for the return code (wsstatus) and for error details returned by the call (res). See Handle GWS REST server errors.

IMPORT FGL clientStub

FUNCTION myWScall()
    DEFINE this clientStub.addUserRequestBodyType
    DEFINE wsstatus INTEGER
    DEFINE res STRING

    LET this.user_name= "Mike Pantock"
    # ...
  
    CALL clientStub.addUser(this.*)RETURNING wsstatus, res
    CASE wsstatus
       WHEN clientStub.C_SUCCESS
         DISPLAY "Success adding new user"
       # … function code
       OTHERWISE
         DISPLAY "Unexpected error :", wsstatus, res
    END CASE
    
END FUNCTION