Using RESTful attributes

RESTful attributes can be set on the attribute clause of input parameters, the function attribute clause, and the attribute clause of return values.

Function input parameter attributes

A RESTful web service can have input parameters. The type of input parameter is defined by the ATTRIBUTES property. Table 1 lists the types. Additional parameters can be specified to provide a name or description; and depending on the parameter type, other attributes might identify the parameter as optional or specify a supported data format.

PUBLIC FUNCTION function-name(
    parameter-name INTEGER ATTRIBUTES(WSHeader, WSName = "id"),
    parameter-name INTEGER ATTRIBUTES(WSParam, WSDescription="Value to be used")
    # ...
    )
    # ...
END FUNCTION
Table 1. Input parameter types
Parameter type Description Other attributes allowed
WSParam The parameter holds a template path.
WSHeader The parameter holds a custom header.
WSQuery The parameter holds a query path in the resource URL.
WSCookie The parameter holds a cookie.
Request body (without attributes WSHeader, WSQuery, WSCookie, or WSParam) The parameter is used for transferring data in the request body. Data can be JSON, XML, text, or a file type (such as an image).
Tip: Data of different MIME types can be sent in multiple parts of the same request. See Multipart requests or responses.
WSAttachment The parameter holds the path to a file for attachment.

Function attributes

The function attributes determine the HTTP verb, the resource path, and more. Table 2 lists and describes the attributes you can use in the ATTRIBUTES clause of the function.

PUBLIC FUNCTION function-name(
    #...
    parameter-name INTEGER ATTRIBUTES(WSParam),
    # ...
    )
    ATTRIBUTES(
       WSGet,
       WSPath = '/{parameter-name}/hello',
       WSThrows="404:not found, 500:Internal Server Error",
       WSDescription="Returns an integer and a greeting"
       # ...
       )
     RETURNS ( INTEGER, STRING )
     # ... function code
    
END FUNCTION
Table 2. Function attributes
Attribute type Description
HTTP verb attributes:

An HTTP verb action specifying the operation on a REST resource. For details of specific requirements of each verb, see HTTP verbs and attributes.

WSPath Slash-separated list of path elements and/or value templates identifying the resource URL.
WSDescription Textual description of the function.
WSThrows Colon-separated list of error-definitions as HTTP status code, and/or code with description.
WSRetCode Colon-separated HTTP status success code with description.
WSScope (function) A comma-separated list of security scopes giving access to the resource.

Function return values attributes

A RESTful web service can have return values. The type of return values is defined by the ATTRIBUTES property. Table 3 lists the return types. Additional parameters can be specified to provide a name or description; and depending on the parameter type, other attributes might identify the parameter as optional or specify a supported data format.

PUBLIC FUNCTION function-name(
    #...
    parameter-name INTEGER ATTRIBUTES(WSParam),
  
    # ...
    )
    ATTRIBUTES(
       # function attributes ...
       )
    RETURNS ( INTEGER ATTRIBUTE(WSHeader), STRING ATTRIBUTE (WSDescription="Greeting") 
       )
        # function code
        RETURN 3, "Hello world"
END FUNCTION
Table 3 lists and describes the attributes you can use in the ATTRIBUTES clause of function return values.
Table 3. Return values attributes
Return type Description Other attributes allowed
WSHeader The return value contains a custom header.
WSAttachment The return value contains a path to a file for attachment.
Response body (without WSHeader) Denotes the return value is used for transferring data in the response body. Data can be JSON, XML, text, or a file type (like an image).
Tip: Data of different MIME types can be sent in multiple parts of the same response. See Multipart requests or responses