Tuesday 28 January 2014

What is difference between SOAP and REST services

SOAP (Simple Object Access Protocol):
SOAP is a method of transferring messages, or small amounts of information, over the Internet. SOAP messages are formatted in XML and are typically sent using HTTP (hypertext transfer protocol).

REST (Representational state transfer):
REST is a simple way of sending and receiving data between client and server and it don't have any much standards defined, we can send and receive data as JSON, XML or even a Text. Its Light weighted compared to SOAP.

SOAP VS REST
SOAP:

  • SOAP builds an XML protocol on top of HTTP or sometimes TCP/IP.
  • SOAP describes functions, and types of data.
  • SOAP is a successor of XML-RPC and is very similar, but describes a standard way to communicate.
  • Binary data that is sent must be encoded first into a format such as base64 encoded.

REST:
  • REST is very lightweight.
  • Typically uses normal HTTP methods instead of a big XML format describing everything. For example to obtain a resource we use HTTP GET, to put a resource on the server we use HTTP PUT. To delete a resource on the server we use HTTP DELETE.
  • REST typically is best used with Resource Oriented Architecture (ROA).
  • Binary data or binary resources can simply be delivered upon their request.

Why we use REST?
Following are few reasons to use REST:

Since REST uses standard HTTP it is much simpler in just about ever way. Creating clients, developing APIs, the documentation is much easier to understand and there aren’t very many things that REST doesn’t do easier/better than SOAP.

REST permits many different data formats where as SOAP only permits XML. While this may seem like it adds complexity to REST because we need to handle multiple formats. JSON usually is a better fit for data and parses much faster. REST allows better support for browser clients due to it’s support for JSON.

REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached.


Why we use SOAP?
Following are few reasons to use SOAP:

WS-Security
While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features. Supports identity through intermediaries, not just point to point (SSL). It also provides a standard implementation of data integrity and data privacy.

WS-AtomicTransaction
Need ACID Transactions over a service, you’re going to need SOAP. While REST supports transactions, it isn’t as comprehensive and isn’t ACID compliant. Fortunately ACID transactions almost never make sense over the internet. REST is limited by HTTP itself which can’t provide two-phase commit across distributed transactional resources, but SOAP can.

WS-ReliableMessaging
Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying. SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries.

No comments:

Post a Comment