Versions Compared

Key

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

...

It is important to understand that the GetObject service returns a handle to a JSON object. This is useful because it can be shared with other services (referred to as companion services) that use a handle to update a resource object. The AddProperty service will be used to add a simple name/value pair to the resource object . Here is a sample code snippetlike so:

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

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:

Code Blocknoformat
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

...