GET Method Examples

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

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;

If you return an object that has a reference to the another object, the related object is also returned as part of the XML or JSON response. This can result in an excessively‑large response.

The following method returns a customer's name in response to a GET request in which the customer identifier is supplied.

getCustomerName(pId: Integer): String;
vars
    customer: Customer;
begin
    // allCustomers is keyed on the customer id
    customer := app.myRoot.allCustomers.getAtKey(pId);
    if not customer = null then
        return customer.name;
    else
        return "";
    endif;
end;