What is difference between soap and rest
This question is raised many times when some new web service or integration environment is set up. Which one is better.
I know some basic difference,below mentioned :
(1)Rest is based on http protocol (get,put,post,delete) , treating everything as a resource.
whereas SOAP is transport agnostic
(2)Soap works only with xml , Rest works with json/xml both.
(3)rest do not provide schema definition when implemented as json,
Soap will always provide schema definitions.
It will be easy to understand request/response schema and
their data type constraints when viewing schema information via WSDL by any client.
(4)The step of wsdl creation makes it difficult to make any changes in your
schema classes while implementing in soap.
Rest implementation is quite easy, we just need to make changes in pojo classes.
(5)Soap provides default error handling via faults.
We can also create our own custom faults.
In Rest we need to handle all error messages explicitly.
(6)Soap provides SoapHandler to intercept request both at client/server side
with both request/response.
we can use filters of j2ee or interceptors of Spring to intercept calls.
(7)Soap is fixed defined set of protocol, whereas rest is architectural style.
While implementing REST, developers can follow any rule,
for example
not using http protocol in well defined way.
While in Soap message part is defined as envelope.
one envelope=header+body+fault+attachment
I am still learning these concepts and had not worked on security of these services in both rest and soap.
According to me the best answer is "It depends on requirement".
Now I want to know which requirements favour which implementation?
When should soap be preferred and when REST? Please explain with an example.
Also please correct me if I am wrong somewhere.
useful link
Thanks
Use REST for
Totally stateless operations: If you need stateless CRUD (Create, Read, Update, and Delete) operations, then REST is it
Caching situations: if the information can be cached because of the totally stateless operation
Limited bandwidth: SOAP XML response consumes more bandwidth compared to REST response
Use SOAP for
Asynchronous processing and invocation: if your application needs a guaranteed level of reliability and security
Formal contracts: if both sides (provider and consumer) have to agree on the exchange format
Stateful operations: if the application needs contextual information and conversational state management
Have a look at this article
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With