About RESTful WebService

Source: Internet
Author: User
Tags soap

Recent work related to data interaction with third-party platforms, so it is natural to choose WebService, soap-based WebService is always in use, but the interface document given by the other side provides two ways, one is the way of soap, Another is the webservice of restful style, this article briefly describes what is the webservice of RESTful style and its advantage with soap-based WebService, The next article provides a small example of how to publish a restful style of webservice.

The full name of rest is representation state Transfer, which describes the architectural style of designing a Web application, which is a set of architectural constraints and principles that the application or design that satisfies these constraints and principles is restful. and restful Web services, that's what we call RESTful website services. The rest principle is as follows:

1. The resource is specified by a URI.

In a Web application, all things should have a unique ID, and the uniform concept of representing IDs is: URIs. URIs make up a global namespace, and using URIs to identify your critical resources means that they have a unique, global ID.

2. Explicitly use the HTTP method.

REST requires the developer to explicitly use the HTTP method, and is used in a manner consistent with the protocol definition. This basic REST design principle establishes a one-to mapping between creating, reading, updating, and deleting (create, read, update, and Delete,crud) operations and HTTP methods. Based on this mapping:

    • To create resources on the server, you should use the POST method.
    • To retrieve a resource, you should use the GET method.
    • To change the state of a resource or update it, you should use the PUT method.
    • To delete a resource, you should use the Delete method.
3. Multiple representations of resources.

Provide multiple representations of resources for different needs. The multiple representations described here include XML, JSON, HTML, and so on. That is, the server side needs to provide external resources in various formats for use by different clients. For example, mobile apps can use XML or JSON and server-side communication, while browsers can understand HTML.

4. No status.

Requests to the server should be stateless, and a complete, independent request does not require the server to retrieve any type of application context or State when processing the request. Stateless constraints make changes to the server invisible to the client, because in two successive requests, the client is not dependent on the same server. A client receives a document from a server that contains a link, and when it does some processing, the server goes down, maybe the hard drive is broken and is repaired, and the software needs to be restarted. If the client accesses a link received from this server, it will not notice that the server in the background has changed.

For webservice, which satisfies the above four principles, we call it the restful style of webservice. So what's the advantage relative to the SOAP protocol-based ws,restful-style ws?

The 1.RESTful Web Services interface is easier to use.

While RESTful Web Services uses standard HTTP methods (Get/put/post/delete) to abstract the service capabilities of all Web systems, the difference is that SOAP applications abstract Web services by defining their own personalized interface methods. In contrast, a RESTful Web services interface is simpler.

The advantages of RESTful WEB services using standard HTTP methods, in large terms: standardized HTTP operation methods, combined with other standardized techniques, such as uri,html,xml, will greatly improve the interoperability between systems and systems. Especially in Web applications, the abstraction that RESTful Web services conveys is more natural than the way the web itself works.

At the same time, rrestful WEB services, implemented using the standard HTTP method, also brings some advantages of the HTTP method itself:

  • Non-state sex

    The HTTP protocol is essentially a stateless protocol, where HTTP requests from clients can be isolated from each other, and there is no mutual state dependency. HTTP-based ROA, which implements stateless service request processing logic in a very natural way. For distributed applications, any given two service requests request 1 with request 2, because they do not have a state dependency between them, they do not need to collaborate with each other, the result is: request 1 and request 2 can be executed on any server, Such an application can easily support load balancing (load-balance) on the server side.

  • Security operation and power-reference equality characteristics

    HTTP request should essentially be a secure call, that is: call does not have any side effects, does not cause the server side state changes. For a server, the client makes N-times a GET, haed call to a URI, and its state is the same as not making a call, and no change will occur.

    The put, delte invocation of HTTP has a power-reference equality feature, that is, the client makes N-times a PUT, Delte call to a URI, and the effect is the same as the call to do it once. The GET and HEAD methods of HTTP also have power-reference equality attributes.

    HTTP these standard methods guarantee in principle that your distributed system has these features to help build a more robust distributed system.

2.RESTful WEB Services makes caching easier.

As we all know, for network-based distributed applications, network transmission is an important factor affecting application performance. How to use caching to save the overhead of network transport is an issue that every developer who constructs a distributed network application must consider.

The HTTP protocol conditional HTTP GET request (Conditional get) is designed to save the overhead of network transport between the client and the server, which also provides the possibility for the client to implement the Cache mechanism, including any proxy between the client and the server. The HTTP protocol implements a conditional get request through the HTTP HEADER domain: If-modified-since/last-modified,if-none-match/etag.

REST applications can fully exploit the HTTP Protocol's ability to support caching. When the client first sends an HTTP GET request to the server for content, the content may be cached by the cache server. The next time the client requests the same resource, the cache can give a direct response without requiring the remote server to obtain it. And all of this is transparent to the client.

Iii. Summary

In everyday applications, we have a number of occasions where we can use restful web Services, including interactions between Web systems, mobile clients and Web server-side communications. RESTful Web Services can be better understood only through more restful practices in daily work.

This article is just a rough introduction to restful WEB services, hoping to help readers get a glimpse of the field, and if more in-depth understanding is needed, readers will need to read more information from other aspects and apply it extensively in practice.

Most of the above articles originate from http://express.ruanko.com/ruanko-express_37/technologyexchange6.html.



About RESTful WebService

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.