REST stub file overview

The stub file provides client-side functions that call the operations of a RESTful Web service. It acts as a proxy layer between your client application and the service.

The fglrestful tool generates a stub file (.4gl) from the OpenAPI description of a RESTful Web service. The generated file contains FUNCTION definitions that wrap the service operations and handle requests and responses using the low-level API provided by the com package.

The stub file also defines the data types used by the service operations. These types correspond to the input and output structures defined in the OpenAPI description and exposed by the service.

Using the stub file in a client application

To use the stub file, import it into your client application with an IMPORT FGL statement. Client code calls the stub functions in the same way as local Genero BDL functions. Each call returns the HTTP status and the data returned by the service.

When multiple modules define types with the same name, it is recommended to use fully qualified names to avoid ambiguity.

Example

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)


# Stub file 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


# MAIN module for the client
# Imports the stub file ws_stub generated from the web service

IMPORT FGL ws_stub

DEFINE wsstatus STRING

MAIN
CALL test()
END MAIN

# Function performing a 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
WHEN ws_stub.C_SUCCESS
DISPLAY SFMT("Success status: %1", wsstatus)
OTHERWISE
DISPLAY SFMT("Internal error: %1", wsstatus)
END CASE
END FUNCTION