Archive for the ‘REST’ Tag

Choosing between REST and SOAP interfaces

The REST vs SOAP debate has raged for long on the web and elsewhere. This post—largely an attempt to demystify the jargon—adds my inconsequential perspective to the conversation.

REST (REpresentational State Transfer) and Simple Object Access Protocol (SOAP) are two predominant approaches to building web services today. As a developer, when you consume web services in your application, you can use these interfaces to work with data or perform other operations.

While SOAP has been around longer on the web, RESTful interfaces are fast becoming popular due to their use of standard web semantics (HTTP); intuitive verbs like GET, PUT, POST, and DELETE; and uniform resource identifiers (URIs) to perform data operations. RESTful web services can, typically, return data in many formats—JSON, HTML, XML, CSV, etc— further simplifying common data operations.

SOAP, on the other hand, differs from REST in having built-in error handling and support for advanced enterprise security features. Besides data, SOAP web services often expose a portion of business logic that you can consume in your application. SOAP uses XML as the messaging format for all communication, sometimes leading to verbose messages and the requirement for additional data processing.

Typical applications

Smaller data payloads and support for standard web semantics have contributed to the popularity of RESTful interfaces on the social web for browser-based apps, mobile apps, and apps delivering high interactivity.

RESTful interfaces, however, do not have built-in error handling in their standard implementation, requiring clients to retry a connection in the event of a communication failure. Applications requiring more reliable messaging—for example, eCommerce and banking apps—find value in the robust connection/retry logic built into most SOAP interfaces. Also, the availability of established extension protocols, such as WS-Security, make SOAP interfaces inherently suitable for applications requiring enterprise-grade security.

Other considerations

Consider these additional factors while deciding whether RESTful or SOAP interfaces are appropriate for your application:

  • Caching. RESTful interfaces support easier caching through HTTP caching mechanisms.
  • Compatibility. If you’re leveraging existing SOAP-based middleware services for your application, you’d likely want to stick to using SOAP interfaces.
  • Bandwidth and resources. RESTful interfaces are, generally, more resource-efficient than SOAP interfaces.
  • Development environment. Some developer tools and services; Microsoft technologies, in particular; automate several aspects of building and consuming SOAP web services.

Examples: RESTful and SOAP requests

The following sample RESTful request gets the profile of a Google+ user with the ID, userId:

GET https://www.googleapis.com/plus/v1/people/userId

The Google Developers page, SOAP Primer, lists several examples of SOAP requests, complete with their XML envelopes.

Further reading: