Example: Get operation with WSGet

Example of methods you can use to get data from a resource with the WSGet attribute.

Example using WSGet

In this sample REST function the number of users from the users table of a database is returned.

PUBLIC FUNCTION getNumberUsers()
  ATTRIBUTES(WSGet, 
             WSPath="/users/count",
             WSDescription="Returns a count of users")
  RETURNS INTEGER
    DEFINE cnt INTEGER
    SELECT COUNT(*) INTO cnt FROM users
    RETURN cnt
END FUNCTION

Example using WSGet to return all users

In this function all users are returned. An example of the resource URL is:
http://host:port/gas/ws/r/group/xcf/Account/users
IMPORT com

TYPE profileType RECORD ... END RECORD

PUBLIC FUNCTION getAllUsers() 
  ATTRIBUTES(WSGet,
             WSPath="/users",
             WSDescription="Returns all user profiles",
             WSThrows="400:Invalid,404:not found")
  RETURNS  (
    DYNAMIC ARRAY ATTRIBUTE(WSName="All_users",WSMedia="application/xml") OF profileType 
    ATTRIBUTE(XMLName="User") )

    DEFINE arr DYNAMIC ARRAY OF profileType
 
    # ... function code ...
    
  RETURN arr
END FUNCTION
The output as XML is customized by WSName and XMLName