Configuring callback functions
You configure high-level REST preprocessing and postprocessing of requests via attributes set on functions in your REST web service module.
Preprocessing performs setup operations before a REST operation executes a request and postprocessing performs transformation operations after the request is executed and before the REST response is forwarded to the client. To implement preprocessing and postprocessing, you must add predefined callback functions to your REST web service module. For sample callback functions, go to Examples of callback functions.
- preprocessing can consist of modifying values in the input expected by the REST operation; a database field may have changed and the query needs to be adjusted.
- postprocessing may involve transforming data depending on the content type; an image may need to be resized or data format need to be transformed before being returned to the client.
If a REST operation has no requirements of a callback function, the REST engine returns control back to the operation to continue standard REST service processing.
- Add predefined callback functions in your REST web service module. For sample callback functions, go to Examples of callback functions.
- Define these functions via two attributes, WSPreProcessing and WSPostProcessing.
- Define these functions as private functions to distinguish them from the public functions of your web service.
Predefined order of executing callbacks
-
HTTP incoming callback
-
Depending on the return code, the request may return immediately to the client or continue to process the request.
-
-
REST parameter, query, header, and cookie incoming callback (if any)
-
Allows you to modify a REST parameter before calling a REST operation.
-
-
REST body incoming callback (depending on the request body content-type)
-
Allows you to modify the body before calling the REST operation.
-
-
Execute the standard REST operation
-
HTTP outgoing callback.
-
Depending on the return code, the response HTTP return code can be changed.
-
-
REST header outgoing callback
-
Allows you to modify REST header parameter before returning the response.
-
-
REST body outgoing callback (depending on the response body content-type)
-
Allows you to modify the HTTP returned body.
-
For sample callback functions, go to Examples of callback functions.