Versions Compared

Key

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

...

Therefore, in order to add a complex sub-resource to a resource object, it is necessary to build the sub-resource object using other services (e.g., GetObject, AddProperty, AddSubProperty, etc.) and then use the object handle in the AddSubResourceObject service. Here is how the above code would could be re-written using the AddSubResourceObject service:

Code Block
languagebp
objResource     = HTTP_Resource_Services('GetObject')
If Error_Services('NoError') then
    PropertyNames   = 'type'     : @FM : 'address'            : @FM : 'city'        : @FM : 'county'  : @FM : 'state' : @FM : 'zip'
    PropertyValues  = 'Mailing'  : @FM : 'PO Box 1234'        : @FM : 'New Orleans' : @FM : 'Orleans' : @FM : 'LA'    : @FM : '70116'
    objSubResource  = HTTP_Resource_Services('GetObject')
    HTTP_Resource_Services('AddProperties', objSubResource, PropertyNames, PropertyValues)
    HTTP_Resource_Services('AddSubResourceObject', objResource, 'address', objSubResource)
    PropertyValues  = 'Shipping' : @FM : '6649 N Blue Gum St' : @FM : 'New Orleans' : @FM : 'Orleans' : @FM : 'LA'    : @FM : '70116'
    objSubResource  = HTTP_Resource_Services('GetObject')
    HTTP_Resource_Services('AddProperties', objSubResource, PropertyNames, PropertyValues)
    HTTP_Resource_Services('AddSubResourceObject', objResource, 'address', objSubResource)
    // Serialize the JSON object.
    jsonResource    = HTTP_Resource_Services('GetSerializedResource', objResource)
end

Admittedly, the AddSubResourceObject service appears to require more code to implement than the AddSubResource service. For simple sub-resource objects this is true but as already noted, the AddSubResourceObject service is intended for more complex sub-resource objects. It is also quite useful when another service is responsible for creating the object handles and these are returned conveniently to be used in the AddSubResourceObject service.