WSOptional
Qualifies an attribute as optional in a REST function.
Syntax
WSOptional
Usage
You use this attribute to specify an attribute in a REST function as optional. You set the
WSOptional
attribute in the ATTRIBUTE()
clause of the
parameter.
WSOptional
can be set only with the following attributes:WSOptional
is an optional attribute.
Example optional cookie
IMPORT com
TYPE profileType RECORD
id INT,
name VARCHAR(50),
email VARCHAR(100),
ccode VARCHAR(10)
# ...
END RECORD
DEFINE myError RECORD ATTRIBUTE(WSError="My error")
code INTEGER,
reason STRING
END RECORD
PUBLIC FUNCTION getUsersByCountry(
p_country STRING ATTRIBUTE(WSCookie, WSOptional, WSName = "Preferred_country" ) )
ATTRIBUTES (WSGet,
WSPath="/users",
WSDescription="Get users by country if the cookie is sent by client.",
WSThrows="400:Invalid,404:NotAvailable" )
RETURNS (
DYNAMIC ARRAY ATTRIBUTE(WSName="Users",WSMedia="application/xml,application/json") OF profileType
)
DEFINE countryList DYNAMIC ARRAY OF profileType
IF p_country IS NULL THEN
SELECT * FROM users
ELSE
SELECT * FROM users WHERE @ccode=p_country
END IF
# ... function code ...
RETURN countryList
END FUNCTION