This post covers features of SOAP and REST and basic differences between them.
- SOAP stands for Simple Object Access Protocol
- It is an XML based web service
- Adds a layer on top of the application protocols. HTTP is the widely used application protocol.
- SOAP is considered heavy weight as it provides significant pre-build extensibility in the form of the WS* standards through additional layer.
- Request includes HTTP header, SOAP Envelope (which includes SOAP Header, SOAP Body (which includes XML message))
- As it has additional layer, it supports attaching files in the request which should be in base64 bit format.
- It provides more security than REST.
- REST stands for Representational State Transfer
- REST typically supports all types of text data formats. Widely used formats are XML and JSON
- Uses HTTP protocol only. No another layer on top of HTTP protocol.
- REST is light weight as it leverages HTTP transport and uses all HTTP Action Verbs (POST, GET, PUT, DELETE)
- Request includes just HTTP header and XML/JSON message.
- It doesn’t support attachment of files in the request.
- REST provides security like token based, but comparatively REST security is less than SOAP.
Sample SOAP Request:
A SOAP Message is encoded as an XML document, consisting of an <Envelope> element, which contains an optional <Header> element, and a mandatory <Body> element. The <Fault> element is sub element of Body is used for reporting errors.
SOAP Envelope with SOAP Header.
Sample SOAP Response:
Sample REST Request in XML:
Sample REST Response in XML:
Sample REST Request in JSON:
Testing of SOAP/REST web service Requests can be done using SOAP UI tool.