REST function syntax with RESTful attributes

A RESTful FUNCTION definition is specified with a set of input parameter attributes, function definition attributes, and return attributes that define it as an operation for a REST Web service.

Syntax (RESTful Function ):

[PUBLIC|PRIVATE] FUNCTION function-name (
     { parameter-name data-type [ attributes-list ]
     | record-name record-type INOUT
     }
     [,...]
  )
 [ attributes-list ]
 [ RETURNS returns-specification ]
    [ local-declaration [...] ]
    [ instruction 
    | [ RETURN expression [,...] ]
        [...] 
    ]
END FUNCTION
where attributes-list is:
ATTRIBUTES ( attribute [ = "value" ] [,...] )

where attributes-list of function parameters must be:

ATTRIBUTES (
{ WSParam
| WSHeader
| WSQuery
| WSCookie
| WSAttachment
| WSDescription = "parameter-description"
| WSOptional
| WSName ="alt-name"
| WSMedia = " MIME-type [,...] "
[,...]
} ) 
where attributes-list of the function must be:
ATTRIBUTES ( http-verb [ , rest-function-attribute [,...] ] )  
where http-verb must be one of:
{ WSGet | WSPost | WSPut | WSDelete 
}
where rest-function-attribute can be one of:
{ WSPath = "/{ path-element | value-template } [/...]"
| WSDescription = "function-description"
| WSThrows = " error-definition [,...] "
| WSRetCode = "success-code:description"
| WSScope = "security-scope [,...] "
} 
where error-definition can be:
{ error-code
| error-code:description
| error-code:@variable
}
where returns-specification is:
{ data-type [ attributes-list ]
| ( data-type [ attributes-list ] [,...] )
| ( )
} 
where attributes-list of returns-specification must be:
ATTRIBUTES (
{ WSHeader
| WSAttachment
| WSDescription = "return-description"
| WSName ="alt-name"
| WSMedia = " MIME-type [,...] "
[,...]
} )
  1. path-element is a slash-separated list of path elements.
  2. value-template elements are place holders for a slash-separated list of variable values.
  3. alt-name is an alternative name for parameters or return values in a REST function that improves readability.
  4. MIME-type is a supported data format type, such as TEXT, JSON, XML, or an image format such JPEG, or PNG, etc.

Function with attributes

Function attributes can be used to complete the definition of the function itself, for its parameters and return values:

PUBLIC FUNCTION add(
    p1 INTEGER ATTRIBUTES(WSHeader, WSName = "id"),
    p2 INTEGER ATTRIBUTES(WSParam)
    )
    ATTRIBUTES(
       WSGet,
       WSPath = '/{p2}/hello',
       WSThrows="404:not found, 500:Internal Server Error",
       WSDescription="Returns an integer and a greeting"
       )
     RETURNS (INTEGER ATTRIBUTE(WSHeader), STRING ATTRIBUTE (WSDescription="Greeting") )
        DEFINE var1 INTEGER
        LET var1 = (p1 + p2)
        RETURN var1, "Hello world"
END FUNCTION

For more details see Function attributes. See Using RESTful attributes for examples of use of the attributes in arguments.