Page History
...
Code Block | ||
---|---|---|
| ||
API contacts.ID.GET KeyID = EndpointSegment ColumnNames// Create a JSON object in memory. =If SRP_JSON(objResource, 'FIRST_NAME' : @FM : 'LAST_NAME' : @FM : 'ADDRESS' : @FM : 'CITY' : @FM : 'STATE' : @FM : 'ZIP' PropertyNames = 'firstName' : @FM : 'lastName' : @FM : 'address' : @FM : 'city' : @FM : 'state' : @FM : 'zipCode' // Create a JSON object in memory. objResource = HTTP_Resource_Services('GetObject', 'CONTACTS', KeyID, ColumnNames, PropertyNames) If Error_Services('NoError') then New') then ContactRow = Database_Services('ReadDataRow', 'CONTACTS', KeyID) If Error_Services('NoError') then SRP_JSON(objResource, 'SetValue', 'firstName', ContactRow<CONTACTS_FIRST_NAME$>, 'String') SRP_JSON(objResource, 'SetValue', 'lastName', ContactRow<CONTACTS_LAST_NAME$>, 'String') SRP_JSON(objResource, 'SetValue', 'address', ContactRow<CONTACTS_ADDRESS$>, 'String') SRP_JSON(objResource, 'SetValue', 'city', ContactRow<CONTACTS_CITY$>, 'String') SRP_JSON(objResource, 'SetValue', 'state', ContactRow<CONTACTS_STATE$>, 'String') SRP_JSON(objResource, 'SetValue', 'zipCode', ContactRow<CONTACTS_ZIP$>, 'String') // Serialize the JSON object and release the object from memory. jsonResource = HTTPSRP_Resource_Services('GetSerializedResource', objResource) JSON(objResource, 'Stringify', 'Fast') SRP_JSON(objResource, 'Release') // Set the response body with the serialized JSON object and set the Content-Type response header. HTTP_Services('SetResponseBody', jsonResource, False$, 'application/hal+json') end else // There is an error reading the CONTACTS row. Probably a non-existent row. HTTP_Services('SetResponseError', '', '', 404, 'Contact ' : KeyID : ' does not exist.', FullEndpointURL) end end else // There is an error condition so call the SetResponseError service. HTTP_Services('SetResponseError', '', '', 500, Error_Services('GetMessage')'Unable to create JSON object', FullEndpointURL) end end api |
...