WSOptional

Qualifies a parameter as optional in a REST function.

Syntax

WSOptional

WSOptional is an optional attribute.

Usage

You can set WSOptional on the ATTRIBUTE()clause of a parameter when a function does not require the parameter to be present when a client calls the service. Setting parameters as optional is typically used when defining REST functions in the following situations:

Example: Optional input body

This example sets WSOptional attribute on the parameter (rec) for the input message body.

You must code in the function to have WSContext detect whether the client has sent a body at runtime. If the request does not have an input body parameter, the GWS sets the "NoRequestBody" entry in the WSContext variable to true.

PRIVATE DEFINE Context DICTIONARY ATTRIBUTE(WSContext) OF STRING

PUBLIC
FUNCTION TestRecord(rec RECORD ATTRIBUTE(WSOptional) a INTEGER, b INTEGER END RECORD)
  ATTRIBUTE (WSPut, WSPath="/record")
  RETURNS (INTEGER)
  IF Context.contains("NoRequestBody") THEN
    DISPLAY Context["NoRequestBody"]
    RETURN 0
  ELSE
    RETURN rec.a + rec.b
  END IF
END FUNCTION