NOTE: To clarify, I am referring to remote calls used for both local AJAX requests as well as any public API calls that can be made (including those made by remote servers or clients).
I love ColdFusion components; I think they add a tremendous amount of value to the organization and cohesion of application features. In fact, I am hoping to learn how to use them in much more powerful ways. But, the one feature of ColdFusion components that I've never really been sold on is the remote access method functionality. I understand that this feature makes publishing SOAP-based web services extremely easy; but, outside of SOAP, do remote method calls actually add any value to an application?
Currently, when I need to make remote calls to my application, I simply call my front controller with the appropriate action value. As a matter of habit, I tend to put "api" before my API-based actions:
My front controller then routes the request through my API work flow which uses a JSON-based template rather than my standard page template. See, when you abstract out page requests, you can see that a JSON response and an HTML response are just different types of template rendering (which I think is what ColdBox does with it's render data method?). In doing so, my API calls naturally get hooked into all aspects of my framework including security. But, even more awesome is that by using the front controller, my unified API response and error handling (I always return a 200 on my API responses) can all be done in one place during the API routing.
This all works quite nicely and has provided no points of friction in development. So, I ask myself, what benefit would I have to switching to remote method calls for my API (not including SOAP publishing)? To be honest, I can't really think of any benefits, but I can think of some definite drawbacks:
- I have the overhead of instantiating a new CFC instance for every single CFC-based API call.
- I generally have to break encapsulation with a remote CFC (calling service objects via the APPLICATION scope or other hard-coded factory).
- I have the very inelegant task of removing my OnRequest() application event handler when using remote CFCs.
- You might consider the remote CFC a "Man in the Middle" anti-pattern as it rarely does anything more than call other components.
- Wiring in error handling becomes slightly more complicated.
- Wiring in interceptors becomes slightly more complicated.
- Page requests become decentralized, breaking the front-controller protocol.
Some of these are not huge drawbacks, but they are drawbacks nonetheless. And, with any drawback, I have to ask myself, does the benefit of the new methodology outweigh the drawbacks associated with the shift? As I cannot conjure up any real benefits, I can't say that moving to a remote-CFC-based API would make any sense for me at this time (unless I wanted to publish SOAP web services). What do you all think?