Traditional Culture Encyclopedia - Weather inquiry - What's the difference between REST API and WebService?

What's the difference between REST API and WebService?

From the basic principle level, the difference between REST-style and SOAP-style Web services depends on whether the application is resource-oriented or activity-oriented. For example, in the traditional WebService, the webservice that obtains the weather forecast exposes a Web method: String GetCitywater (String City). RESTful WebService exposes not methods, but objects (resources), which are requested by Http GET, PUT, POST or DELETE operations. In the definition of REST, Web services always use a fixed URI to show (or expose) a resource to the outside world. It can be said that this is a brand-new thinking mode: using unique resource location address URI and HTTP request method to realize the unique description and operation of a resource published on the Internet.

So I understand that the webservice defined for the rest architecture actually defines an excuse specification.

In fact, REST is not a protocol or a standard, but an interpretation of the original intention of Http protocol design. Today, the Http protocol is widely used, and it is increasingly used as a transport protocol, rather than the application protocol originally considered by designers.

The concept of rest can be summed up in the following points:

1. resource-oriented interface design

All interface designs are designed for resources, which is very similar to the difference between our object-oriented and process-oriented designs, except that the operating entities on the network are now regarded as resources, and the design of URI also reflects the positioning design of resources. As will be mentioned later, the API design of some websites is said to be REST design, but it is actually a mixture of RPC and REST, not the idea of REST.

2. CRUD based on abstract operations

This is very simple. Get, put, www. Hbbz08.com post and delete in Http correspond to four operations, namely reading, updating, creating and deleting. If it is only the operation of resources, it is enough to abstract into these four operations, but for some complex business service interface design, such abstraction may not be enough. In fact, this also exposes such problems in the API design of the following websites. If we want to design completely according to the idea of REST, the applicable environment will be limited and not universally applicable.

3.HTTP is an application protocol, not a transport protocol.

This is clearly reflected in the API analysis of major websites. Some websites actually follow the old path of SOAP, saying that they are conceptual designs of REST, but actually they have made a set of private SOAP protocols, so they are called REST-style custom SOAP protocols.

4. Stateless and independent

In fact, this is not only for rest, but also for interface design. It is also the most basic guarantee of scalability and efficiency, even for WebService using SOAP.