SOAP or REST?
If you have ever wondered which form of web services you should use, you are not alone. However, there is no easy answer. In this section, we list the key differences between SOAP and REST services to help you decide which style to choose for your particular case.
- SOAP-based web services are object oriented, and REST-based web services are representation oriented. Without going into detail, this distinction means that you can get started easily with a SOAP-based solution, but a REST-based solution will need additional planning to create a logical hierarchy.
- SOAP-based web services are declarative, use the standard WSDL format to describe them, and have great tooling support. REST-based web services do not yet have a standard for describing services.
- SOAP-based web services support only XML, and REST-based web services can support numerous content types, including JavaScript Object Notation (JSON), and can be accessed directly from JavaScript.
- SOAP 1.1–based solutions do not conform to the HTTP model and hence cannot take advantage of HTTP caching, security, and so on. REST is fully HTTP complaint.
- XML use makes the SOAP format verbose and its performance slower than REST using JSON. However, REST clients may take a longer time when using XML.
- REST generates search-engine optimization (SEO)–friendly endpoints.
As a general rule, REST benefits web services directly accessed from web pages as in the case of XMLHTTPRequests (XHR), and SOAP benefits web services accessed by an intermediate server or middleware.