Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP vs REST, when to use one and not the other?

Tags:

rest

soap

I'm really confused everytime I come around this question, what characteristics would help one choosing SOAP over REST or the other way around?

I mean, besides the fact that REST has a compact format compared to SOAP, and the other "minor" or "technical" differences, what are the "obvious" differences that make one of them more suitable for a project and not the other?

Just for the record, I have read all of the other questions (1|2|3|4) regarding this matter on Stack Overflow, and not one of them answered my question.

like image 379
Shotgun Avatar asked Nov 20 '13 16:11

Shotgun


People also ask

Which has more rules SOAP or REST?

While SOAP and REST share similarities over the HTTP protocol, SOAP is a more rigid set of messaging patterns than REST. The rules in SOAP are important because we can't achieve any level of standardization without them. REST as an architecture style does not require processing and is naturally more flexible.

How do you decide between SOAP and REST?

A general rule of thumb when you're deciding between SOAP and REST for building your API: if you want standardization and enhanced security, use SOAP. If you want flexibility and efficiency, use REST. For specific use cases of when to use SOAP vs REST, check out the table below.

Can you use both REST and SOAP?

Existing frameworks limit a particular endpoint to be either SOAP or REST. A soaprest endpoint is specified as a SOAP web service using WSDL, but will also accept REST invocations, and will respond according to how a request was invoked. This gives one the advantages of both SOAP and REST in a single web service.


2 Answers

If you just want a simple, visual guide to help you measure SOAP and REST against your applications requirements...

Vijay Prasad Gupta has put together a simple, helpful flow-chart.

Direct link to flow chart: https://drive.google.com/file/d/0B3zMtAq1Rf-sdVFNdThvNmZWRGc/edit

Link to article: https://www.linkedin.com/pulse/20140818062318-7933571-soap-vs-rest-flowchart-to-determine-the-right-web-services-protocol-for-your-needs

like image 80
JTech Avatar answered Sep 21 '22 07:09

JTech


The difference between REST and SOAP is fundamental, yet they're not that dissimilar. Ultimately, you still need to transfer exactly the same information in order to perform a particular abstract operation. It's entirely easy to make REST rather low-performing by choosing poorly what information to return, and SOAP with MTOM can transfer large binary chunks efficiently. There's even the possibility to use non-XML encodings and connected transports (e.g., XMPP) with SOAP that can make it more efficient than REST.

So don't worry about that!

A much more relevant thing to think about is that SOAP continues to have significantly more advanced tooling support in some languages, and that other languages strongly prefer REST. For example, if you want a Java client for your service, you'll be able to get going with SOAP in minutes: just put the WSDL location through a tooling engine and you've got yourself a basic client. On the other hand, if you're working with a Javascript client then you'll absolutely prefer to deal with the REST interface; Javascript works great with REST.

A key thing to note here is that you can have your service support both SOAP and REST at once (you might need to put them on different endpoints, but that's not very onerous). I do this with a service I support (using Java and Apache CXF) and the overhead of doing both is minimal: the key is that I need a clean abstract interface behind the scenes that both the SOAP and REST interfaces use.

like image 45
Donal Fellows Avatar answered Sep 22 '22 07:09

Donal Fellows