Monday, October 11, 2010

REST or SOAP Services – When do I use which ?

Our customers often ask if it is better to use REST services or SOAP services and much like other similar questions, it depends very much on what you are trying to achieve.


REST based services lend themselves very well to simple, stateless requests for information or for updating a single resource that is updated in isolation. Due to the statelessness of REST requests, each one must work or fail in isolation so it must be clear that recovery of multiple actions undertaken with REST can only be backed out using a compensating transaction. In other words, your application needs to manually undo any changes that it has made. REST also sometimes requires that a number of different formats of errors may be returned which may make error recovery a little convoluted.


SOAP servers lend themselves better to more complex tasks where requests and services tend to depend on each other. For example where two services need to be updated together or not at all. Programmatically it offers a more controlled way to work with the service through service specific SOAP headers for example. It also tends to produce errors or problems in a consistent way using SOAP Faults.


If  I were to hazard some simple rules of thumb:



-         Use REST when simple unrelated updates are required or where the latest set of a specific set of data is required.



-         Use SOAP where more complex related updates are required or where information needs to be gathered and aggregated from multiple sources.


....but be warned, like many other rules of thumb it’s the exception that makes the rule so choose whatever is best for your particular requirement to satisfy the business need. The SOA Gateway gives you the ability to have both a REST or SOAP based access to the same service and thus gives you the ability to see which one fits best for your specific requirement.

No comments:

Post a Comment