Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For simple database related resources, the GetDatabaseItem service (a member of the HTTP_Resource_Services module) can be used with minimal code. Just get the Key ID from the prepopulated EndpointSegment variable and pass in the name of the database table:

Code Block
languagebp
API contacts.ID.GET

   KeyID   = EndpointSegment

   HTTP_Resource_Services('GetDatabaseItem', 'CONTACTS', '', KeyID)

end api

...

One of the drawbacks of calling the GetDatabaseItem service is that property names are formatted with underscores (i.e., how they appear in the dictionary) rather than as camel case (which is the conventional format for JSON objects). Another drawback is that the GetDatabaseItem service attempts to return all column data (both physical and calculated). Sometimes this is undesirable since This might be undesirable if some of the data is meaningless in the resource object being returned to the client. Consider the picture property in the above resource object. The value is a reference to It references an image file stored locally on the server and , which has no value to the client. To resolve both of the above items, we will take advantage of the optional ColumnNames and ItemArrayLabel arguments. To keep the remaining our sample code simple and concise, we will limit our resource to just the FIRST_NAME, LAST_NAME, ADDRESS, CITY, STATE, and ZIP database columns:

...

No Format
{
    "address": "6649 N Blue Gum St",
    "city": "New Orleans",
    "firstName": "James",
    "lastName": "Butt",
    "state": "LA",
    "zipCode": "70116"
}

...

Pros:

  • Simple to call.
  • It creates the response body, content-type, and status code automatically.

Cons:

  • Deprecated (but there are no plans to remove it

...

  • ).
  • Can support HATEOAS (via the optional SelfURL argument), but it is limited.
  • Cannot be overridden to include the Key ID within the resource object.