Function attributes

Function attributes can be used to add definition information about the function, its parameters and its return values.

Purpose of function attributes

Function attributes can be used to define properties for the function itself, for the parameters accepted by the function, and for the returned values/types.

Function attributes are typically used to define RESTful Web services with high-level framework.

Usage

Function, parameter and return value attributes are specified with the ATTRIBUTES() clause. The ATTRIBUTES() clause contains a comma-separated list of attributes. An attribute can be a name=value pair, or single name for a boolean attribute:
ATTRIBUTES( WSScope='book.write', WSPUT, WSPath='{id}', ... )
The ATTRIBUTES() clause can be specified:
  • after a type of parameter in the ( ) parameter list, to define parameter attributes.
  • after the closing brace of the parameter list, to define function attributes.
  • after a type in the RETURNS clause, to define return value attributes.

Example

TYPE SimpleBookType RECORD ... END RECORD
TYPE BookType RECORD ... END RECORD

PUBLIC FUNCTION UpdateBookById(
    id INTEGER ATTRIBUTES( WSParam ),
    b SimpleBookType ATTRIBUTES( WSMedia='application/json' )
    ) ATTRIBUTES( WSScope='book.write, book.read',
                  WSPUT,
                  WSPath='/{id}',
                  WSDescription="Update book title and author for given id",
                  WSThrows="400:Invalid,404:NotAvailable" )
  RETURNS (
    BookType ATTRIBUTES( WSMedia='application/json,application/xml' )
  )

  DEFINE ret BookType

  # ... code to update the book ...

  RETURN ret.*

END FUNCTION