Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare and contrast REST and SOAP web services? [duplicate]

I currently figure out the similar is both using internet protocol (HTTP) to exchange data between consumer and provider.

The difference is:

  1. SOAP is a XML-based message protocol, while REST is an architectural style
  2. SOAP uses WSDL for communication between consumer and provider, whereas REST just uses XML or JSON to send and receive data
  3. SOAP invokes services by calling RPC method, REST just simply calls services via URL path
  4. SOAP doesn't return human readable result, whilst REST result is readable with is just plain XML or JSON
  5. SOAP is not just over HTTP, it also uses other protocols such as SMTP, FTP, etc, REST is over only HTTP

That's everything I know as the differences between them. Could anyone correct me and add more.

like image 386
Huppo Avatar asked Jun 11 '12 07:06

Huppo


People also ask

What are the differences and similarities between REST and SOAP?

REST is a set of guidelines that offers flexible implementation, whereas SOAP is a protocol with specific requirements like XML messaging. REST APIs are lightweight, making them ideal for newer contexts like the Internet of Things (IoT), mobile application development, and serverless computing.

What's the difference between a SOAP and a REST web services?

SOAP is a protocol whereas REST is an architectural pattern. SOAP uses service interfaces to expose its functionality to client applications while REST uses Uniform Service locators to access to the components on the hardware device. SOAP needs more bandwidth for its usage whereas REST doesn't need much bandwidth.

What is the difference between web service and RESTful web services?

Web services are a type of API, which must be accessed through a network connection. REST APIs are a standardized architecture for building web APIs using HTTP methods.

What is difference between SOAP & REST API?

REST APIs access a resource for data (a URI); SOAP APIs perform an operation. REST is an architecture that's more data-driven, while SOAP is a standardized protocol for transferring structured information that's more function-driven.


2 Answers

SOAP uses WSDL for communication btw consumer and provider, whereas REST just uses XML or JSON to send and receive data

WSDL defines contract between client and service and is static by its nature. In case of REST contract is somewhat complicated and is defined by HTTP, URI, Media Formats and Application Specific Coordination Protocol. It's highly dynamic unlike WSDL.

SOAP doesn't return human readable result, whilst REST result is readable with is just plain XML or JSON

This is not true. Plain XML or JSON are not RESTful at all. None of them define any controls(i.e. links and link relations, method information, encoding information etc...) which is against REST as far as messages must be self contained and coordinate interaction between agent/client and service.

With links + semantic link relations clients should be able to determine what is next interaction step and follow these links and continue communication with service.

It is not necessary that messages be human readable, it's possible to use cryptic format and build perfectly valid REST applications. It doesn't matter whether message is human readable or not.

Thus, plain XML(application/xml) or JSON(application/json) are not sufficient formats for building REST applications. It's always reasonable to use subset of these generic media types which have strong semantic meaning and offer enough control information(links etc...) to coordinate interactions between client and server.

  • For more details regarding control information I highly recommend to read this: http://www.amundsen.com/hypermedia/hfactor/
  • Web Linking: https://www.rfc-editor.org/rfc/rfc5988
  • Registered link relations: http://www.iana.org/assignments/link-relations/link-relations.xml

REST is over only HTTP

Not true, HTTP is most widely used and when we talk about REST web services we just assume HTTP. HTTP defines interface with it's methods(GET, POST, PUT, DELETE, PATCH etc) and various headers which can be used uniformly for interacting with resources. This uniformity can be achieved with other protocols as well.

P.S. Very simple, yet very interesting explanation of REST: http://www.looah.com/source/view/2284

like image 76
ioseb Avatar answered Oct 13 '22 06:10

ioseb


In day to day, practical programming terms, the biggest difference is in the fact that with SOAP you are working with static and strongly defined data exchange formats where as with REST and JSON data exchange formatting is very loose by comparison. For example with SOAP you can validate that exchanged data matches an XSD schema. The XSD therefore serves as a 'contract' on how the client and the server are to understand how the data being exchanged must be structured.

JSON data is typically not passed around according to a strongly defined format (unless you're using a framework that supports it .. e.g. http://msdn.microsoft.com/en-us/library/jj870778.aspx or implementing json-schema).

In-fact, some (many/most) would argue that the "dynamic" secret sauce of JSON goes against the philosophy/culture of constraining it by data contracts (Should JSON RESTful web services use data contract)

People used to working in dynamic loosely typed languages tend to feel more comfortable with the looseness of JSON while developers from strongly typed languages prefer XML.

http://www.mnot.net/blog/2012/04/13/json_or_xml_just_decide

like image 4
StartupGuy Avatar answered Oct 13 '22 04:10

StartupGuy