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/xcf/users
IMPORT com
TYPE profileType RECORD
id INT,
name VARCHAR(50),
email VARCHAR(100)
END RECORD
PUBLIC FUNCTION getAllUsers()
ATTRIBUTES(WSGet,
WSPath="/users",
WSDescription="Returns all user profiles",
WSThrows="400:Invalid,404:not found")
RETURNS DYNAMIC ARRAY OF profileType
DEFINE arr DYNAMIC ARRAY OF profileType
# ... function code ...
RETURN arr
END FUNCTION