Example: Update resource with WSPut
Update a resource with the WSPut attribute.
Example updating a resource with WSPut
In this sample REST function a user resource is updated.
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 updateUsers(
id INTEGER ATTRIBUTES(WSParam),
thisUser profileType)
ATTRIBUTES(WSPut,
WSPath="/users/{id}",
WSDescription='Update a user profile',
WSThrows="400:@userError")
RETURNS STRING
DEFINE ret STRING
WHENEVER ERROR CONTINUE
UPDATE users
SET name = thisUser.name,
email = thisUser.email
WHERE @id = id
WHENEVER ERROR STOP
CASE
WHEN SQLCA.SQLCODE == 0
LET ret = SFMT("Updated user with ID: %1",id)
WHEN SQLCA.SQLCODE == NOTFOUND
LET ret = SFMT("No row was found with ID: %1",id)
OTHERWISE
LET userError.message = SFMT("SQL error:%1 [%2]",SQLCA.SQLCODE, SQLERRMESSAGE)
CALL com.WebServiceEngine.SetRestError(400,userError)
END CASE
RETURN ret
END FUNCTION