Main
Standards

« ASP.NET 2.0 Portal Framework | Main | BEA unveils AquaLogic product line for SOA. »

May 20, 2005

SOAP vs. REST [ XML/HTTP ] :The Web Services debate.

There is no doubt that web services will continue to be a common practice when developing web applications, the capability of accessing business functions in a platform & device agnostic manner has made the technology a champion among J2EE, .NET, PHP and other web platforms. But even though the concept is clearcut, there seems to be two emerging camps defining how to implement a web service: SOAP and XML/HTTP (a.k.a REST-Representational State Transfer ).

[Entry continues to the left and below ad ]

Before you jump the gun on the lesser "advertised" XML/HTTP REST approach as not being a web service, the fact remains that it complies with a web service definition : The capability of accessing information in a platform transparent manner. And if you consider the thorough REST support offered by early web services adopters like Amazon and EBay, you can conclude that REST is not a fad.

The most obvious difference between both approaches is the actual payload that is transferred through the wire, which directly translates into distinct implementation details on both client & server. Lets explore the differences.

A REST design implies that a web application is equipped for returning a plain and simple XML fragment as a response to a URL request. Lets assume you make a call into the following address: http://www.yoursite.com/restapp/weather.php?city=sandiego. A REST type application would return a payload like the following snippet back to the caller:

<weather>
  <city>San Diego</city>
  <date>05/21/05</city>
  <high>85</high>
  <low>70</low>
</weather>

It's that simple, the server side application is implemented in PHP -- or any other language for that matter -- and can be called & interpreted from any type of client because the payload is XML. Now lets analyze the SOAP approach and see how its different.

For starters, the actual client call to a SOAP enabled service is not as simple as attaching your parameters to the URL -- like a typical POST done by an HTML form -- the expected payload by the processing server has to adhere to a SOAP schema, like the following :

<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   
  <SOAP-ENV:Body>
         <ns1:getCityWeather xmlns:ns1="Weather">
           <op1 xsi:type="xsd:string"> San Diego </op1>
         </ns1:getCityWeather>
    </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>

Sending this payload to the server implies a more extensive client design process, and receiving a response also requires provisions to process a SOAP payload instead of a plain XML fragment.

You may now be asking yourself which approach is better and under what circumstances, here is my take on both designs.

REST - XML/HTTP : Simplicity

If you see the capability of publishing some business data to your clients so they can process it in something other than a browser as a nice feature, then using a REST design could be a wise choice. Using XML over HTTP you shed yourself of other web services issues like dealing with WSDL and UDDI, in part because REST is so simplified it doesn't require these enterprise type services.

For example, being a wholesaler and publishing catalog data to retailers via a web service is a nice feature to have, but it is not something that a retailer can't do without if unavailable for a few hours or a day. What I am getting at with the previous example is that the caller of the service can afford to reissue failed attempts without any consequences.

Take Amazon and EBay they offer REST access for their product information, news feeds like Atom and RSS are also designed around REST, their primary characteristic is that even though the information can be consumed by and device or process, the consequences of multiple calls or failures is not transcendental.

SOAP : Enterprise

A SOAP structure is complex in nature for a reason : resilience. Even though the previous SOAP snippet did not show it, a SOAP payload can include a series of service characteristics like priority, expiration, security credentials, routing information and transactional behaviors.

These types of policies included in your service call or response are all but essential in some cases. Any value added transaction is a candidate for using SOAP's provisions, a financial operation is an obvious case, another would be an order fulfillment done through web services.

Using SOAP also brings you into the circle of using web services contracts -- WSDL ("Web Services Description Language") -- and the capabilities of publishing them to a central directory -- UDDI ("Universal Description, Discovery and Integration") -- both of which are also a central part of using web services in an enterprise type setting.

If your intent on using web services is to publish non-critical data, a REST design can speed up your development time with workable tradeoffs, on the other hand, if you see web services as a cornerstone to your business, then you might as well bite the bullet and use the SOAP approach.

Update: Published a lengthier article on REST - Simplicity in Web Services design , that includes more technical differences to a SOAP stack and references to REST's use in production environments.

[Comments below ad ]

Posted by Daniel at May 20, 2005 7:04 PM


Comments

thanks for give me idea about xml/http rest and soap

Posted by: simhadri at June 4, 2005 6:07 AM

Excellent comments and good job of clearly articulating something that could have been made very complex.

Posted by: Scott Converse at June 22, 2005 8:21 AM

I think that you meant to say GET instead of POST here:

is not as simple as attaching your parameters to the URL -- like a typical POST done by an HTML form...

I think that SOAP is all about building a standard and extensible platform. I think that SOAP layer allows us to separate infrastructure from application and build an infrastructure platform. As a developer I am only responsible for the application layer while the platform vendor is responsible for other aspects that you mentioned. This separation helps in achieving interoperability and reducing overall costs. As SOAP platforms evolves application layer can be reused.

Posted by: Oleg at November 7, 2005 10:22 AM

Great Article.

Posted by: Shrivardhan at June 3, 2007 10:30 AM

Wonderful artical with simple distinction of widely debated topic.

Posted by: Parama at October 18, 2007 3:00 PM


Post a comment




Remember Me?

(you may use HTML tags for style)

Track back Pings

Track Back URL for this entry:
http://www.webforefront.com/mtblog/mt-tb.cgi/9.

 
XHTML 1.1   Powered by Movable Type 3.33