The purpose of this blog posting is a quick review, for myself, on the differences and the advantages and disadvantages of RESTful services versus SOAP or XML-RPC. When is it appropriate to be using RESTful services? When is it appropriate to use SOAP? Well, if you are consuming web services, the answer is pretty simple: Use whichever is appropriate for the service being published. You don’t really have much of a choice in that situation.
The next two circumstances deserve a little more attention. First, when you are both producer and consumer of the webservice, and second, when you are the producer of the webservice for one or more outside entities, possibly the public. Now, which do you use? Well, here’s the basic rundown on each, for comparison’s sake.
REST (REpresentational State Transfer) – ie. the object is represented by the URL
1) On the plus side, it is SIMPLE, and so requires less handholding for outside entities to make use of it, and it does not require any special tools.
2) It is lightweight, so less code is required, typically, and smaller data transfers (less XML overhead)
3) The results are human readable, in most cases.
-) On the downside, it is not supported by Apache Axis 1.4, which is the version used in ColdFusion 7.
SOAP (Simple Object Access Protocol) or XML-RPC (Remote Procedure Calls):
1) It can be simple, if you have the right tools.
2) It is strongly typed and explicit, essentially establishing a contract between the client code and the service provider.
The REST approach was embraced by David H. and is highlighted in his keynotes on Ruby on Rails. The virtues of REST are touted by Dave Thomas, the Pragmatic Programmer, and others. It tends to be the favored approach for developers in Ruby on Rails, PHP, and a signature prescription for a Web 2.0 style web application.
SOAP is more “old school”, and tends to be the favored approach by Java developers.
A new driver for the SOAP versus REST pro-con discussion is the widespread emergence of mobile phones with internet capability. The assumptions about connections and bandwidth usually assigned to desktop computers do not necessarily apply to mobile phones. So, the lower overhead of a RESTful approach does contribute to the argument for using REST rather than SOAP.
Both sides have good arguments behind their use. In general, though, the trend is moving away from SOAP and XML-RPC toward the more RESTful approach, largely due to the successes it has brought sites that use REST. In an culture where there is a strong sentiment toward SOAP, likely the case in an old Java shop, it may not be the battle that you wish to engage in.