Versions Compared

Key

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

...

In the above code, the GetObject service is called without any arguments. This simply returns a handle to an empty resource object. It doesn't have to be completely empty, but for the sake of a simple demonstration we'll start with an empty resource object and use the AddProperty service to add two properties: firstName and lastName. The values are hardcoded, although production code will most likely draw from a database row or other digital source. We finish by calling the GetSerializedResource service so that we get a stringified JSON object that we can inspect or use in our API. Here is what our resource object looks like:

noformat
Code Block
languagejs
{
   "firstName":"William",
   "lastName":"Hudson"
}

Another service that might add a little more convenience is AddProperties. It's a wrapper around the AddProperty service that allows the developer to pass in an @FM delimited list of property names and values into a single call. For example:

Code Block
languagebp
objResource     = HTTP_Resource_Services('GetObject')
If Error_Services('NoError') then
    PropertyNames   = 'firstName' : @FM : 'lastName'
    PropertyValues  = 'William'   : @FM : 'Hudson'
    HTTP_Resource_Services('AddProperties', objResource, PropertyNames, PropertyValues)
    // Serialize the JSON object.
    jsonResource    = HTTP_Resource_Services('GetSerializedResource', objResource)
end

...