com.WebServiceEngine.SetRestStatus

Manages HTTP response status codes (200 - 299) for a REST high-level web service function.

Syntax

com.WebServiceEngine.SetRestStatus(
   code INTEGER )
  1. code defines a standard HTTP response status code (200 - 299) as defined in RFC 2616 Section 10.2

Usage

You use this method in a REST web service function to dynamically change the HTTP return code. By default, the REST operation returns 200 (success), 204 (if there is no body), and so on, but this method can be called to set the return code to any value in the range from 200 to 299.

To support the Swagger and OpenAPI specification, Genero Web Services supports the "2XX" value, which is a specific code that can be set in the WSRetCode attribute to define a range of response codes between 200 and 299.

In the call to the SetRestStatus() method, the 2XX value must be specified in the WSRetCode declaration of the function; otherwise, the method fails and returns an error code of -15570.
Warning:

You cannot call the SetRestStatus() method outside a REST operation.

In the examples Example 1: managing user input and Example 2: managing zero different uses of the method are shown.

Example 1: managing user input

In this example, the call to SetRestStatus(205) will send the code 205 to "Reset Content" in the response.

PUBLIC
FUNCTION TestOne(x_one STRING)
  ATTRIBUTE (WSPOST,WSPath="/one",WSRetCode='2XX:HELLO')
  RETURNS (STRING)
  IF NOT x_one.equalsIgnoreCase("REGULAR") THEN
    CALL com.WebServiceEngine.SetRestStatus(205)
  END IF
  RETURN x_one
END FUNCTION

Example 2: managing zero

In this example you code to trap when a parameter value is zero. In the call to the SetRestStatus()method the status code 288 is returned.

PUBLIC
FUNCTION TestTwo(one INTEGER, two INTEGER )
  ATTRIBUTE (WSPOST,WSPath="/two",WSRetCode='2XX')
  RETURNS (INTEGER)
  IF one == 0 THEN
    CALL com.WebServiceEngine.SetRestStatus(288)
  END IF
  RETURN one + two
END FUNCTION