Step 2: Listen for requests

Listen for an incoming request.

Define an object variable using the com.HTTPServiceRequest class identifier. This variable will reference the incoming HTTP service request. In addition, define an INTEGER variable to hold an error status, if needed.
DEFINE ret INTEGER
DEFINE req com.HTTPServiceRequest
Start the server engine with the method com.WebServiceEngine.Start().
DEFER INTERRUPT

# Start the server

DISPLAY "Starting server..."

# Starts the server on the port number specified by the FGLAPPSERVER environment variable
#  (EX: FGLAPPSERVER=8090)
 
CALL com.WebServiceEngine.Start()
DISPLAY "The server is listening."

Listen for an incoming request using com.WebServiceEngine.getHTTPServiceRequest. When a request is received, the variable req references the HTTP service request object. You can use the same object to send a response.

Include a CATCH block to trap runtime exceptions. For a RESTful Web service, include a check for error -15565, which is returned when an incoming request cannot be returned.
...
# create the server
WHILE TRUE
    TRY
        LET req = com.WebServiceEngine.getHTTPServiceRequest(-1)
        ... parse and process the request ...
    CATCH
        LET ret = STATUS
        CASE ret
        WHEN -15565
            DISPLAY "Disconnected from application server."
            EXIT WHILE
        OTHERWISE
            DISPLAY "[ERROR] " || ret
            EXIT WHILE
        END CASE
    END TRY
END WHILE

For more information see com.WebServiceEngine methods.

In the next step we extract the details of the incoming request, Step 3: Parse the request