Comparison of SOAP and REST API

SOAP (Simple Object Access Protocol) defines a very strong type of messaging framework that relies heavily on XML and architecture. REST- stands for State Transfer - is an architectural style that uses existing and widely adopted technologies (especially HTTP ) and does not create any new standards. REST can structure data into XML , YAML or any other machine-readable format, but JSON is usually preferred .

SOAP and REST- both support building SOA- based applications. From a business and architectural perspective, which option to use depends largely on what is actually needed. By looking at their advantages and disadvantages in certain environments, and understanding the scope of your project, you can make the most informed decision. So let us list their main differences, which will help you choose one of the two.

Comparison of SOAP and REST API

Underlying protocol

SOAP itself is a protocol used to develop SOAP- based APIs (via HTTP ).

REST is almost synonymous with HTTP , and the REST specification has not mandated it from beginning to end .

Data format

SOAP only relies on XML to provide messaging services. In some cases, such as accessing Web services through javascript , the messaging can become extremely complicated.

REST can use data in Comma Separated Values ​​( CSV ), JavaScript Object Notation ( JSON ), and Really Simple Syndication ( RSS ). The point is that you can get the desired output in the language required by the application in an easy-to-parse form.

Stateful

RESTful web services are completely stateless. It is the customer's sole responsibility to manage the state of the conversation. The server did not help you.

Usually, the SOAP Web services are stateless, but you can easily change the code on the server the SOAP API into a stateful .

Cache

REST provides a good caching infrastructure through the HTTP GET method, so that the response data can be marked as cacheable or non-cacheable. The ETag standard head is to implement caching to provide value you want to calculate what should be an inexpensive way of a good way.

When using HTTP as the transport mechanism, SOAP is sent through HTTP POST requests. Since HTTP POST is non-idempotent, it cannot be cached at the HTTP level. Therefore, you should use the information provided in the Response Caching Optimization Module to cache the SOAP response.

Use of HTTP verbs

REST is mainly used for HTTP . It uses HTTP GET , POST , PUT , DELETE and PATCH methods to perform different CRUD operations.

SOAP also defines the binding to the HTTP protocol. When bound to HTTP , all SOAP requests are sent via HTTP POST .

Safety

REST is based on HTTP- itself is a very insecure protocol. It supports basic authentication and communication encryption via TLS . Any other security measures should be additionally implemented on the server.

WS-SECURITY on SOAPSecurity been well standardized, WS-SECURITY has many functions and is easy to implement application code.

Asynchronous processing

Creating / updating resources is very time consuming and may require asynchronous request processing. In this case, REST suggests to return the HTTP response code, 202 Accepted, and send the queue location, where the task completion status will be updated regularly. REST won the JAX-RS itself of the asynchronous API of good support.

If your application requires guaranteed reliability and security, then SOAP 1.2 provides other standards to ensure this type of operation. WSRM  - things like WS-Reliable Messaging .

Overview

Overall, REST is easier to develop because it takes advantage of the existing Web and has limited freedom (fewer choices to make and therefore simpler). SOAP provides a variety of options, and the development is slightly more difficult, but it provides more options and scope of work.

 

Guess you like

Origin blog.csdn.net/allway2/article/details/109537931