REST stub file overview

The stub file acts as a proxy to the Web service, making it easy to use a Web service in your client app.

The fglrestful tool can generate a stub file (.4gl) for access by a Genero Web Services (GWS) client application for any REST Web service supporting the OpenAPI specification. It creates functions in Genero BDL that perform requests and return responses and data from the Web service. The functions in the client stub implement the standard low-level API HTTP classes of the com package of the GWS.

The stub file defines data types for the input and output records matching those generated on the server side. In your Web service client app, you create calls to the stub file functions to perform operations on the resources of the Web service.

Reference records

You will find details for the parameters and return values to use with functions from the OpenAPI description (see Generate service description on demand ) or from the generated functions in the stub file.

In your client app, you must import the stub file using an IMPORT FGL statement. It is recommended that you reference types using their fully-qualified names in case the same name exists in different modules.

Using stub files

This example shows how data types and functions defined for a Web service created with Genero BDL are generated in the stub file and called by the client accessing the Web service.

Study this example to learn how to use the stub file in your Genero client application.

Server (myService)

# Module with the Web service operations

PUBLIC TYPE recType RECORD
     idtype SMALLINT,
     nametype STRING
 END RECORD

PUBLIC FUNCTION echoRec(
     in recType)
     ATTRIBUTES(WSPost, WSPath = "/testTypeRec", WSRetCode = "202:Accepted")
     RETURNS(recType)
     DEFINE OUT recType
 
     LET OUT = in
     RETURN out.*
 END FUNCTION

Stub file (ws_stub)

# The stub file with code generated by fglrestful from the Web service (myService)

# components/schemas/recType
 PUBLIC TYPE recType RECORD
     idtype INTEGER,
     nametype STRING
 END RECORD

PUBLIC FUNCTION echoRec(
    p_body recType)
    RETURNS(INTEGER, recType)
 
    # ... function code generated by fglrestful tool

 END FUNCTION

Client

# The MAIN module for the client
# Imports the stub file ws_stub generated from Web service using fglrestful

IMPORT FGL ws_stub

DEFINE wsstatus STRING

MAIN
   CALL test()
END MAIN

# Function performs call to the stub function 
FUNCTION test()
     DEFINE in, out ws_stub.recType
 
     LET in.idtype = 1
     LET in.nametype = "test STRING"
 
     CALL ws_stub.echoRec(in) RETURNING wsstatus, out
      
     CASE wsstatus
        # C_SUCCESS is a constant defined in the ws_stub
       WHEN ws_stub.C_SUCCESS
         DISPLAY SFMT("Success status:  %1", wsstatus)
       OTHERWISE
         DISPLAY SFMT(" Internal error: %1", wsstatus)
     END CASE
END FUNCTION