Publish a REST service
In publishing the service you provide your service to users who can access it on the net.
Functions of your service you want to publish, must be defined as PUBLIC
. When
you publish a service, only the functions that are public are generated in the OpenAPI specification
file. Functions that are private, are not available as operations of the service and are therefore
not generated.
To publish a service, for example, in the service's main module, you:
- Import the service module
- Call on the
RegisterRestService
function - Call on the
com.WebServiceEngine.ProcessServices
to start the service
IMPORT com
IMPORT FGL serviceModule
MAIN
DEFINE ret INTEGER
CALL com.WebServiceEngine.RegisterRestService("serviceModule", "MyService")
DISPLAY "Server started"
CALL com.WebServiceEngine.Start()
WHILE TRUE
LET ret = com.WebServiceEngine.ProcessServices(-1)
CASE ret
WHEN 0
DISPLAY "Request processed."
WHEN -1
DISPLAY "Timeout reached."
WHEN -2
DISPLAY "Disconnected from application server."
EXIT PROGRAM # The Application server has closed the connection
WHEN -3
DISPLAY "Client Connection lost."
WHEN -4
DISPLAY "Server interrupted with Ctrl-C."
WHEN -9
DISPLAY "Unsupported operation."
WHEN -10
DISPLAY "Internal server error."
WHEN -23
DISPLAY "Deserialization error."
WHEN -35
DISPLAY "No such REST operation found."
WHEN -36
DISPLAY "Missing REST parameter."
OTHERWISE
DISPLAY "Unexpected server error " || ret || "."
EXIT WHILE
END CASE
IF int_flag<>0 THEN
LET int_flag=0
EXIT WHILE
END IF
END WHILE
DISPLAY "Server stopped"
END MAIN
In the sample, all public Web service functions of the module "serviceModule.4gl" are registered with the GWS server as a REST service.
The "serviceModule" identifies the name of the service module. "MyService" is the public name given to the REST service.