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.

IMPORT com

TYPE profileType RECORD
     id INT,
     name VARCHAR(50),
     email VARCHAR(100)
   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