255

For now I have a slight idea about the differences between SOAP and RESTful services.

My question is when I should use SOAP, and when I should use RESTful; which one is "better" when it comes to performance/speed or request handling?

I'm implementing it for the first time in RESTful (Java) and I want know more about it; I've dealt with SOAP before.

This is a follow-up question to this post.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Gandalf StormCrow
  • 24,470
  • 66
  • 159
  • 248
  • 12
    There are tons of questions like this, this is most likely a duplicate of at least one of those: http://stackoverflow.com/questions/76595 http://stackoverflow.com/questions/209905 http://stackoverflow.com/questions/90451 http://stackoverflow.com/questions/90451 http://stackoverflow.com/questions/993184 http://stackoverflow.com/questions/28950 – Joachim Sauer Jan 25 '10 at 13:56
  • See also, `SOAP RPC contrast`: http://en.wikipedia.org/wiki/Representational_State_Transfer#Concept – trashgod Jan 25 '10 at 16:41

11 Answers11

249

REST is almost always going to be faster. The main advantage of SOAP is that it provides a mechanism for services to describe themselves to clients, and to advertise their existence.

REST is much more lightweight and can be implemented using almost any tool, leading to lower bandwidth and shorter learning curve. However, the clients have to know what to send and what to expect.

In general, When you're publishing an API to the outside world that is either complex or likely to change, SOAP will be more useful. Other than that, REST is usually the better option.

dj_segfault
  • 11,455
  • 3
  • 26
  • 35
  • 5
    From the web service consumer side, when should you use REST and when should you use SOAP? (assuming both options are provided). From what I understand, REST should be used in cases when the consumer wants to access the web services through a browser. Since browsers can understand both XML and JSON. If the web services are to be consumed programmatically there doesn't seem to be any major advantage. In fact SOAP seems to fit the bill since they are more organized (WSDL). I would appreciate to have your thoughts on this. – Andy Dufresne Apr 02 '13 at 05:53
  • 2
    Andy, if the API is simple and the existing calls are not likely to change, REST will be fine. The upside of SOAP having this formal process for describing itself is if the service changes, you'll know right away and be able to adapt to it more easily. – dj_segfault Apr 03 '13 at 13:00
  • Swagger can take care of publishing the API for restful web services. – akhil_mittal May 16 '17 at 12:13
  • seems to me soap is hard contract based and not easy to fiddle with but rest being easy to modify as there is no fixed contract but without a proper document can bring more bugs in the system which brings to me the question is this downside of rest overwhelms the benefits of being light and easy to change. – xpioneer Aug 23 '20 at 07:23
69

REST vs. SOAP Web Services

I am seeing a lot of new web services are implemented using a REST style architecture these days rather than a SOAP one. Lets step back a second and explain what REST is.

What is a REST web service?

The acronym REST stands for representational state transfer, and this basically means that each unique URL is a representation of some object. You can get the contents of that object using an HTTP GET, to delete it, you then might use a POST, PUT, or DELETE to modify the object (in practice most of the services use a POST for this).

Who's using REST?

All of Yahoo's web services use REST, including Flickr and Delicious.

APIs use it, pubsub, bloglines, Technorati, and both eBay, and Amazon have web services for both REST and SOAP.

Who's using SOAP?

Google seams to be consistent in implementing their web services to use SOAP, with the exception of Blogger, which uses XML-RPC. You will find SOAP web services in lots of enterprise software as well.

REST vs. SOAP

As you may have noticed the companies I mentioned that are using REST APIs haven't been around for very long, and their APIs came out this year mostly. So REST is definitely the trendy way to create a web service, if creating web services could ever be trendy (lets face it you use soap to wash, and you rest when your tired). The main advantages of REST web services are:

  • Lightweight - not a lot of extra XML markup Human Readable Results

  • Easy to build - no toolkits required. SOAP also has some advantages:

Easy to consume - sometimes Rigid - type checking, adheres to a contract Development tools For consuming web services, its sometimes a toss up between which is easier. For instance Google's AdWords web service is really hard to consume (in ColdFusion anyway), it uses SOAP headers, and a number of other things that make it kind of difficult. On the converse, Amazon's REST web service can sometimes be tricky to parse because it can be highly nested, and the result schema can vary quite a bit based on what you search for.

Whichever architecture you choose make sure its easy for developers to access it, and well documented.

Freitag, P. (2005). "REST vs SOAP Web Services". Retrieved from http://www.petefreitag.com/item/431.cfm on June 13, 2010

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
salman khalid
  • 4,544
  • 4
  • 24
  • 31
43

SOAP

Simple Object Access Protocol (SOAP) is a standard, an XML language, defining a message architecture and message formats. It is used by Web services. It contains a description of the operations.

WSDL is an XML-based language for describing Web services and how to access them. It will run on SMTP, HTTP, FTP, etc. It requires middleware support and well-defined mechanism to define services like WSDL+XSD and WS-Policy. SOAP will return XML based data

REST

Representational State Transfer (RESTful) web services. They are second-generation Web services.

RESTful web services communicate via HTTP rather than SOAP-based services and do not require XML messages or WSDL service-API definitions. For REST middleware is not required, only HTTP support is needed. It is a WADL standard, REST can return XML, plain text, JSON, HTML, etc.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
kapil das
  • 1,881
  • 25
  • 29
42

REST is an architecture.
REST will give human-readable results.
REST is stateless.
REST services are easily cacheable.

SOAP is a protocol. It can run on top of JMS, FTP, and HTTP.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Kalidoss.M
  • 479
  • 5
  • 6
32
  1. REST has no WSDL (Web Description Language) interface definition.

  2. REST is over HTTP, but SOAP can be over any transport protocols such as HTTP, FTP, SMTP, JMS, etc.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
CharithJ
  • 42,659
  • 20
  • 104
  • 124
26
  • REST stands for representational state transfer whereas SOAP stands for Simple Object Access Protocol.

  • SOAP defines its own security where as REST inherits security from the underlying transport.

  • SOAP does not support error handling, but REST has built-in error handling.

  • REST is lightweight and does not require XML parsing. REST can be consumed by any client, even a web browser with Ajax and JavaScript. REST consumes less bandwidth, it does not require a SOAP header for every message.

    • REST is useful over any protocol which provide a URI. Ignore point 5 for REST as mentioned below in the picture.

SOAP vs. REST

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
IRSHAD
  • 2,302
  • 25
  • 35
  • 3
    REST - not only over HTTP, over any protocol which provide a URI. – Raúl Dec 02 '16 at 07:28
  • 2
    SOAP has built-in error handling mechanism and sends back error info. https://www.tutorialspoint.com/soap/soap_fault.htm – vimal krishna Dec 03 '16 at 17:30
  • @Raúl, yes you are right – IRSHAD Dec 06 '16 at 06:23
  • Uhhmm SOAP is very human readable. It is XML afterall. RPC style SOAP has also been deprecated and document based service definitions are the preferred style. Saying rest is better in performance that SOAP is absolute nonsense. A REST service in a infinite loop will never perform as fast a hello world SOAP service. – Namphibian Jul 20 '17 at 04:23
23

REST vs. SOAP

SOAP:

► SOAP is simple object access protocol that run on TCP/UDP/SMTP.
► SOAP read and write request response messages in XML format.
► SOAP uses interface in order to define the services.
► SOAP is more secure as it has its own security and well defined standards.
► SOAP follows RPC and Document style to define web services.
► SOAP uses SOAP-UI as client tools for testing.

REST

► REST is representational state transfer that uses underlying HTTP protocols.
► REST is stateless.
► REST is an architectural style that is used to describe and define web services.
► REST can read and write request response messages in JSON/XML/Plain HTML.
► REST uses URI for each resource that is used in web service.A resource can be image text method etc.
► REST uses set of verbs, like HTTP's GET, POST, PUT, DELETE.
► REST is easy to develop and easy to manage as compared to SOAP UI.
► REST has light-weight client tools or plugins that can easily be integrated inside a browser.
► REST services are cacheable.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Waqas Ahmed
  • 3,743
  • 3
  • 31
  • 42
  • REST can use any other transport protocol (FTP, SMTP etc) - only condition is that they shall implement a URI scheme. See - http://stackoverflow.com/a/10976047/760393 – Raúl Dec 02 '16 at 07:29
14

Difference between REST and SOAP:

Enter image description here

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
yogesh wadhwa
  • 693
  • 8
  • 16
8

SOAP Web services:

  1. If your application needs a guaranteed level of reliability and security then SOAP offers additional standards to ensure this type of operation.
  2. If both sides (service provider and service consumer) have to agree on the exchange format then SOAP gives the rigid specifications for this type of interaction.

RestWeb services:

  1. Totally stateless operations: for stateless CRUD (Create, Read, Update, and Delete) operations.
  2. Caching situations: If the information needs to be cached.
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
6

SOAP web service always make a POST operation whereas using REST you can choose specific HTTP methods like GET, POST, PUT, and DELETE.

Example: to get an item using SOAP you should create a request XML, but in the case of REST you can just specify the item id in the URL itself.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Anil Kumar B
  • 109
  • 1
  • 3
2

REST is easier to use for the most part and is more flexible. Unlike SOAP, REST doesn’t have to use XML to provide the response. We can find REST-based Web services that output the data in the Command Separated Value (CSV), JavaScript Object Notation (JSON) and Really Simple Syndication (RSS) formats.

We can obtain the output we need in a form that’s easy to parse within the language we need for our application.REST is more efficient (use smaller message formats), fast and closer to other Web technologies in design philosophy.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
vidya k n
  • 109
  • 1
  • 3