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.
- Import the service module.
- Call on the
com.WebServiceEngine.RegisterRestService()
method to register the service. - Call on the
com.WebServiceEngine.ProcessServices()
method to start the service.
Web service main module
This is an example of a module that runs a Web service. The IMPORT FGL
statement
imports the service module "serviceModule", allowing its public-defined variables and functions to
be referenced.
In the call to the RegisterRestService()
method, the Web service module
"serviceModule.4gl" is registered with the GWS server as a REST service. The
name of the service is set to "MyService". This is the public name given to the REST service, used
in the URI endpoints to access its resources.
The call to ProcessServices()
is made to start the service process within a
WHILE
loop. Within the loop requests for services are processed and various Web service engine errors are handled. The Web
service runs until interrupted.
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