GET Method Example

The method in the following example returns a Customer object in XML or JSON in response to a GET request in which the customer identifier is specified.

getCustomer(pId: Integer): Customer updating;
vars
    customer: Customer;
begin
    // allCustomers is keyed on the customer id
    customer := app.myRoot.allCustomers.getAtKey(pId);
    if customer = null then
        // Setting HTTP status optional - you could simply return a 'null' customer
        self.httpStatusCode := 404;
        return null;
    else
        // Make an object to return and avoid returning references
        return customer.cloneSelf(true);
    endif;
end;