I'm writing a remote method to accept data from a remote system in a
post and then do some local processing and then persist it to my
database. I know how to tell the event handler in the controller that
it can be called remotely but how would I document/enforce an
interface? I know I could write a webservice outside of coldbox but I
don't really need the overhead for those particular situation. I just
want to say that fields x,y,z are required and fields a,b,c,d are
optional and then be sure that those fields exist in the incoming
Normally I'd just write a function and use cfargument tags, but as I
understand coldbox, the http post/get will be all bundled together
into the Event collection which is then handled off to my event
handler in the controller and the only cfargument I'm using there is
What are the suggestions for best practices?
You could still write a method and declare the arguments, and then have the event handler pass off to it using argumentCollection: event.getCollection().
That's certainly a thought. I just wasn't sure if there was a "proper"
way to do it using a proxy or an interceptor or some such.
Heh. I’m sure there are a number of ways that you could go about accomplishing the goal. One of the beautiful things about using OO techniques is that if you’ve properly encapsulated the logic, you can “get it running” and then quickly and easily change it out later if you need to change it.
Are you saying the call is remote as flex remoting? or Ajax Remote? or webservice? How ?
Have you seen the coldbox proxy support?
You can build as many proxy objects and then create a very clear remote API throught it and then delegate back into the event-driven architecture.
In this particular case the call is a simple http post (possibly a
get) that is sending 7 variables to me that I need to run some logic
on and persist the results. In general, I'm trying to expose a couple
of services, some for sending data, some for receiving. Thus far we
don't need the overhead of a full blow webservice. We are just
exchanging data back and forth in JSON format over normal http calls.
I'll look into the proxy functions more. I figured that that might be
the way to go but I know that there are a number of ways to do it, so
I figure it doesn't hurt to inquire about best practices.
If they are post calls, then I would use the event-driven nature of coldbox by just posting to special events.
Remote is your handler and call is the method you expose. Then you can use handler interceptors for any type of validation of massaging of the data, security, etc (preHandler, postHandler). Then from those events, use renderData() to send back JSOn or whatever you need.
This way, you create a clear handler for these operations (separation), highly documented and unit testable.
I always use the CB-proxy, no matter if ti's a get or post call
So all ajax calls go through the proxy.
Like Luis said, the event-driven nature of coldbox stays intact.
My ColdBoxProxy looks like this:
<cfcomponent name="coldboxproxy" output="false"
<!--- You can override this method if you want to intercept before
and after. --->
<cffunction name="process" output="true" access="remote"
returntype="any" hint="Process a remote call and return data/objects
<cfset var results = "">
<!--- Default: WDDX --->
<cfparam name="url.returnFormat" type="string" default="">
<!--- Process --->
<cfset results = super.process(argumentCollection=arguments)>
<!--- Which return format? --->
<!--- Event handler should return JSON, XML or a simple value --->
<cfheader name="expires" value="Mon, 03 Sep 1973 00:00:01 GMT">
<cfheader name="pragma" value="no-cache">
<cfheader name="cache-control" value="no-cache">
<!--- WDDX --->