Examples of callback functions
In the code samples are examples of all the preprocessing and postprocessing BDL functions you can use in your REST web service module.
These samples are intended as templates for your callback functions. Copy those that you need to your REST web service module and adapt them to your needs.
Types of callback
- Preprocessing callbacks
- These are functions you use to preprocess the query, header, body, and input parameter values of
the REST request. They are identified with the name
*PreCallback
and are set with theWSPreProcessing
attribute. If the content type of the body of the incoming request uses a JSON, XML, or text format, use the appropriate preprocessing function.The
HTTPPreCallback
function may be used to validate the request as it is called first in the callback order. This function either returns a zero to continue to process the REST operation, or a HTTP return code to return to the client. - Postprocessing callbacks
- These are functions you use to process the return header and body of the REST request. They are
identified with the name
*PostCallback
and are set with theWSPostProcessing
attribute. If the content type of the return body of your request uses JSON, XML, or text format, use the appropriate postprocessing function.The
HTTPPostCallback
function may be used to validate the response as it is called first in the callback order after executing the REST operation. This function either returns a zero to continue to process the REST operation, or a HTTP return code to return to the client.
Examples of preprocessing and postprocessing BDL functions
# REST Web service module
PRIVATE # HTTP incoming request callback
FUNCTION HTTPPreCallback() ATTRIBUTES (WSPreProcessing) RETURNS (INTEGER)
DISPLAY "Doing HTTP Pre processing"
DISPLAY Context["RequestOPERATION"] # Display current REST service
RETURN 0 # HTTP ret code, or 0 to continue standard REST service processing
END FUNCTION
PRIVATE # HTTP response callback
FUNCTION HTTPPostCallback() ATTRIBUTES (WSPostProcessing) RETURNS (INTEGER)
DISPLAY "Doing HTTP Post processing"
DISPLAY Context["RequestOPERATION"] # Display current REST service
RETURN 0 # HTTP ret code, or 0 to continue standard REST service processing
END FUNCTION
PRIVATE # REST Query string incoming callback
FUNCTION QueryPreCallback(query STRING, value STRING) ATTRIBUTES (WSPreProcessing="wsquery") RETURNS (STRING)
DISPLAY "Query:",query
DISPLAY "Value:",value
RETURN value # new query value
END FUNCTION
PRIVATE # REST Parameter incoming callback
FUNCTION ParamPreCallback(param STRING, value STRING) ATTRIBUTES (WSPreProcessing="wsparam") RETURNS (STRING)
DISPLAY "Param:",param
DISPLAY "Value:",value
RETURN value # new parameter value
END FUNCTION
PRIVATE # REST Header incoming callback
FUNCTION HeaderPreCallback(header STRING, value STRING) ATTRIBUTES (WSPreProcessing="wsheader") RETURNS (STRING)
DISPLAY "Header:",HEADER
DISPLAY "Value:",value
RETURN value # new header value
END FUNCTION
PRIVATE # REST Header outgoing callback
FUNCTION HeaderPostCallback(header STRING, value STRING) ATTRIBUTES (WSPostProcessing="wsheader") RETURNS (STRING)
DISPLAY "Header:",HEADER
DISPLAY "Value:",value
RETURN value # new header value
END FUNCTION
PRIVATE # REST JSONObject incoming callback
FUNCTION JSONObjectPreCallback(obj util.JSONObject) ATTRIBUTES (WSPreProcessing) RETURNS (util.JSONObject)
DISPLAY "Doing JSON pre processing"
RETURN obj# new JSONObject value
END FUNCTION
PRIVATE # REST JSONObject outgoing callback
FUNCTION JSONObjectPostCallback(obj util.JSONObject) ATTRIBUTES (WSPostProcessing) RETURNS (util.JSONObject)
DISPLAY "Doing JSON Post processing"
RETURN obj # modified JSONObject value
END FUNCTION
PRIVATE # REST JSONArray incoming callback
FUNCTION JSONArrayPreCallback(obj util.JSONArray) ATTRIBUTES (WSPreProcessing) RETURNS (util.JSONArray)
RETURN obj # modified JSONArray value
END FUNCTION
PRIVATE # REST JSONArray outgoing callback
FUNCTION JSONArrayPostCallback(obj util.JSONArray) ATTRIBUTES (WSPostProcessing) RETURNS (util.JSONArray)
RETURN obj # modified JSONArray value
END FUNCTION
PRIVATE # REST XML incoming callback
FUNCTION XMLPreCallback(xml xml.DomDocument) ATTRIBUTES (WSPreProcessing) RETURNS (xml.DomDocument)
return xml # modified XML value
END FUNCTION
PRIVATE # REST XML outgoing callback
FUNCTION XMLPostCallback(xml xml.DomDocument) ATTRIBUTES (WSPostProcessing) RETURNS (xml.DomDocument)
RETURN xml # modified XML value
END FUNCTION
PRIVATE # REST TXT incoming callback
FUNCTION TextPreCallback(s STRING) ATTRIBUTES (WSPreProcessing) RETURNS (STRING)
RETURN s # modified STRING value
END FUNCTION
PRIVATE # REST TXT outgoing callback
FUNCTION TextPostCallback(s STRING) ATTRIBUTES (WSPostProcessing) RETURNS (STRING)
RETURN s # modified STRING value
END FUNCTION