SOAP vs REST (differences)

前端 未结 12 2083
忘了有多久
忘了有多久 2020-11-22 11:40

I have read articles about the differences between SOAP and REST as a web service communication protocol, but I think that the biggest advantages for REST over SOAP are:

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 12:09

    REST(REpresentational State Transfer)
    REpresentational State of an Object is Transferred is REST i.e. we don't send Object, we send state of Object. REST is an architectural style. It doesn’t define so many standards like SOAP. REST is for exposing Public APIs(i.e. Facebook API, Google Maps API) over the internet to handle CRUD operations on data. REST is focused on accessing named resources through a single consistent interface.

    SOAP(Simple Object Access Protocol)
    SOAP brings its own protocol and focuses on exposing pieces of application logic (not data) as services. SOAP exposes operations. SOAP is focused on accessing named operations, each operation implement some business logic. Though SOAP is commonly referred to as web services this is misnomer. SOAP has a very little if anything to do with the Web. REST provides true Web services based on URIs and HTTP.

    Why REST?

    • Since REST uses standard HTTP it is much simpler in just about ever way.
    • REST is easier to implement, requires less bandwidth and resources.
    • REST permits many different data formats where as SOAP only permits XML.
    • REST allows better support for browser clients due to its support for JSON.
    • REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached.
    • If security is not a major concern and we have limited resources. Or we want to create an API that will be easily used by other developers publicly then we should go with REST.
    • If we need Stateless CRUD operations then go with REST.
    • REST is commonly used in social media, web chat, mobile services and Public APIs like Google Maps.
    • RESTful service return various MediaTypes for the same resource, depending on the request header parameter "Accept" as application/xml or application/json for POST and /user/1234.json or GET /user/1234.xml for GET.
    • REST services are meant to be called by the client-side application and not the end user directly.
    • ST in REST comes from State Transfer. You transfer the state around instead of having the server store it, this makes REST services scalable.

    Why SOAP?

    • SOAP is not very easy to implement and requires more bandwidth and resources.
    • SOAP message request is processed slower as compared to REST and it does not use web caching mechanism.
    • WS-Security: While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features.
    • WS-AtomicTransaction: Need ACID Transactions over a service, you’re going to need SOAP.
    • WS-ReliableMessaging: If your application needs Asynchronous processing and a guaranteed level of reliability and security. Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying.
    • If the security is a major concern and the resources are not limited then we should use SOAP web services. Like if we are creating a web service for payment gateways, financial and telecommunication related work then we should go with SOAP as here high security is needed.

    source1
    source2

提交回复
热议问题