Example 4 : Asynchronous HTTP DELETE request

IMPORT com
 
MAIN 
  DEFINE req com.HTTPRequest
  DEFINE resp com.HTTPResponse
  DEFINE url STRING
  DEFINE quit CHAR(1)
  DEFINE questionStr STRING
  DEFINE timeout INTEGER
  TRY 
    WHILE TRUE
      PROMPT "Enter http url you want to delete ? " 
         FOR url ATTRIBUTES (CANCEL=FALSE)
      LET req = com.HTTPRequest.Create(url)
      CALL req.setMethod("DELETE")
      CALL req.doRequest()
      # Retrieve asynchronous response for the first time
      LET resp = req.getAsyncResponse() 
      CALL Update(resp) RETURNING questionStr,timeout
      WHILE quit IS NULL OR ( quit!="Y" AND quit!="N" )
        PROMPT questionStr FOR CHAR quit 
          ATTRIBUTES (CANCEL=FALSE,ACCEPT=FALSE,SHIFT="up")
          ON IDLE timeout
          IF resp IS NULL THEN # If no response at first try, 
                                # retrieve it again
            LET resp = req.getAsyncResponse() # as we now have time
            CALL Update(resp) RETURNING questionStr,timeout 
          END IF
        END PROMPT 
      END WHILE
      IF quit == "Y" THEN
        EXIT PROGRAM 
      ELSE
        LET quit = NULL
      END IF
    END WHILE
  CATCH
    DISPLAY "ERROR :",STATUS,SQLCA.SQLERRM
  END TRY
END MAIN

FUNCTION Update(resp)
  DEFINE resp com.HTTPResponse
  DEFINE ret STRING
  IF resp IS NOT NULL THEN
    IF resp.getStatusCode() != 204 THEN
    LET   ret = "HTTP Error ("||resp.getStatusCode()||")
      :"||resp.getStatusDescription()||". Do you want to quit ? "
    ELSE 
      LET   ret = "HTTP Page deleted. Do you want to quit ? "
    END IF 
  RETURN ret, 0
  ELSE 
    LET ret = "Do you want to quit ? "
    RETURN ret, 1
  END IF
END FUNCTION