SOAP REST
SOAP is a protocol. REST is an architectural style.
SOAP can’t use REST because it is a protocol. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.
Uses services interfaces to expose the business logic. Uses URI to expose business logic.
JAX-WS is the java API for SOAP web services. JAX-RS is the java API for RESTful web services.
SOAP standards should be strictly followed since it is protocol REST does not define too much standards like SOAP
requires more bandwidth and heavy requires less bandwidth and resource
SOAP defines its own security RESTful web services inherits security measures from the underlying transport.
SOAP permits XML data format only. REST permits different data format such as Plain text, HTML, XML, JSON etc.
SOAP is less preferred REST more preferred than SOAP

When to use SOAP?

  • Exposes operation over a logic – It aligns to enterprises application needs and goals
  • When using SMTP(Simple Mail Transfer Protocol) and JMS
  • It could be used when multiple systems are involved in Distributed Environment I.E. System A -> System B -> System C
  • In a complex system like banks WSDL serves as a agreed agreement for interpreting data over different system
  • SOAP uses two varieties,Synchronous Messaging over HTTP,Asynchronous Messaging over HTTP
    With synchronous messaging, the Requestor makes a request and the transport layer code blocks waiting for a response from the Provider. The Requestor receives the response on the same HTTP connection that the Requestor initially established to send the request. Synchronous exchange is usually easier to implement and requires that the Provider be able to generate a response in a short time, specifically in a time less than the HTTP timeout value(generally 120sec). [A single HTTP Connection is used that itself behaves Synchronously]
    With asynchronous messaging, the Requestor is able to release transport specific resources once the request is acknowledged by the responder, knowing that a response will eventually be received. When the Provider completes the processing of the message it sends a response back to the Requestor over a new HTTP connection. [Here we utilize two HTTP Connections to implement an asynchronous messaging]

    1. first HTTP Connection is used that for sending the Request and receiving an acknowledgement HTTP Response 200/OK
    2. second HTTP Connection is used for receiving the callback and responding HTTP Response 200/OK]
  • SOAP has a option for Service Registry where you can see who is registered for services and who could consume our services
  • Ideal for enterprise application where security(WS-Security), transaction(WS-AT) and reliability(WS-RM) are main concerns

When to use REST?

  • Exposes Resources over data – Simple point to pint communication between two systems System A -> System B
  • While working with synchronous environment
  • Could be used if you want to communicate over Stateless protocol like HTTP/HTTPS
  • It could be consumed by any Client simple by using AJAX and Javascript
  • Rest mostly uses resource as nouns and verbs like delete user, add user, edit user in its URI model
  • REST is purely an HTTP transport based call and you will receive a response say 200 OK. Synchronous messaging. The disadvantage is in order to
    have good scale-ability the architecture should be asynchronous
  • Ideal for mashup where datas are taken from various resources like twitter and less secured data communication