Example: create resource with WSPost
Create a new resource with the WSPost attribute.
Example creating resource with WSPost
In this sample REST function a new user resource is created. The user record is defined as a data type in the module. This is referenced in the input parameter thisUser.
IMPORT com
TYPE profileType RECORD ... END RECORD
PUBLIC DEFINE userError RECORD ATTRIBUTE(WSError="User error")
message STRING
END RECORD
PUBLIC FUNCTION createUser( thisUser profileType )
ATTRIBUTES(WSPost,
WSPath="/users",
WSDescription="Create a user profile",
WSThrows="400:@userError")
RETURNS STRING
DEFINE ret STRING
WHENEVER ERROR CONTINUE
INSERT INTO users VALUES (thisUser.*)
WHENEVER ERROR STOP
CASE
WHEN SQLCA.SQLCODE == 0
LET ret = SFMT("Created user: %1",thisUser.name)
OTHERWISE
LET userError.message = SFMT("SQL error:%1 [%2]",SQLCA.SQLCODE, SQLERRMESSAGE)
CALL com.WebServiceEngine.SetRestError(400,userError)
END CASE
RETURN ret
END FUNCTION