Publish REST service module
Publish a service with one resource.
To publish a service, in the service's main module you code to:
- Import the service module.
- Call on the
com.WebServiceEngine.RegisterRestService()
method to register the service. - Call on the
com.WebServiceEngine.Start
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".
In the call to the RegisterRestService()
method, the GWS REST engine registers
the Web service module as a REST service. In the example, "MyService" is the public name of the REST
service, which users will see in the service's URI endpoints.
In the call to ProcessServices()
, the service process starts within a
WHILE
loop. The GWS REST engine processes requests for resources and handles Web service engine errors. The Web service runs
until interrupted.
IMPORT com
IMPORT FGL serviceModule
MAIN
DEFINE ret INTEGER
DEFER INTERRUPT
CALL com.WebServiceEngine.RegisterRestService("serviceModule", "MyService")
DISPLAY "Server started"
CALL com.WebServiceEngine.Start()
CONNECT TO "myDatabase""+driver='dbmsqt'"
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