I’ve answered my own question… got it to work…
Here is the code in case anyone else comes across this thread.
First create an interceptor cfc. Mine is saved as interceptors/SimpleResponse.cfc
component{
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
function preProcess( event, interceptData, rc, prc ){
prc.response = wirebox.getInstance( "SimpleResponse" );
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
}
Second, create models/SimpleResponse.cfc
component extends="coldbox.system.web.context.Response" hint=""{
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
function init(){
super.init()
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/**
* Returns a standard response formatted data packet using the information in the response
*
* @reset Reset the 'data' element of the original data packet
*/
struct function getDataPacket( boolean reset = false ){
var packet = {
"error" : getError() ? true : false,
"messages" : getMessages(),
"data" : getData()
};
// Are we reseting the data packet
if ( arguments.reset ) {
packet.data = {};
}
return packet;
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
}
Note that I’ve removed the ‘pagination’ key completely. Compare the getDataPacket()
method to the one in coldbox.system.web.context.Response
and you’ll see the difference.
Third, add the interceptor to config/Coldbox.cfc
interceptors = [
{
class : "interceptors.SimpleResponse",
name : "SimpleResponse",
properties : {}
}
];
Fourth, reinit your Coldbox app.
And Lastly, yell out, BLOODY AMAZING!
Working with CB is a real treat!
My response now looks like this:
{
"data": {
"hash": "$2a$12$.8E7U9SRc2ZYgKv9KtzsI.Z9hVI8IJK3d0DcLoU7pCe5sSbSqxrUe"
},
"error": false,
"messages": []
}