Brief Introduction to rest Architecture

Source: Internet
Author: User
Tags representational state transfer
Http://www.nowamagic.net/librarys/veda/detail/885why is rest?

Rest is the abbreviation of representational state transfer ", he is a term proposed by Dr. Roy Thomas Fielding in his paper titled neural tural styles and the design of network-based software ubuntures. Rest is a loosely coupled application designed based on named resources rather than messages. For example, it uses uniform resource locators (URL), uniform resource identifiers (URI), and uniform resource names (URN) form-a style of loose coupling Web applications rather than messages.

Rest cleverly leverages the proven web infrastructure-HTTP. All things on the Web (pages, images, etc.) are essentially resources. While rest is based on named resources rather than messages, which limits the exposure of underlying technologies and provides convenience for loose coupling in application design. The charm of rest is that everything can be a resource and the representation methods can be different.

For example, a http://www.nowamagic.net/librarys/veda/articles/888, the URL represents a Resource-a resource whose article is 888. When you request this resource, the http get command is called. Note that the URL is based on nouns. Verb-based version (probably similar to http://www.nowamagic.net/librarys/veda/articles? Id = 888) will violate the rest principle because it embeds a message in the form of articles.

Rest advantages

Rest improves the portability of user interfaces across multiple platforms, and simplifies server components to improve system scalability. The most important thing is to separate user interfaces and data storage, so that different user terminals can enjoy the same data.

1. Stateless

Stateless is another layer of specification added Based on Customer-server constraints. Communication is essentially stateless, that is, every request from the customer to the server must contain all the information required to understand the request. This specification improves the visibility of the system (stateless makes it unnecessary for the client and server to save the detailed information of the other party, and the server only needs to process the current request without having to know all the request history ), reliability (stateless reduces the number of tasks that the server can recover from a local error), scalability (stateless allows the server to easily release resources, because the server does not have to save the status in multiple requests ). At the same time, the disadvantages of this specification are also obvious. Because the state data cannot be stored in the shared context on the server, the overhead of sending duplicate data in a series of requests is increased, it seriously reduces the efficiency.

2. Cache

To improve the inefficiency of the stateless network, we add cache constraints. Cache constraints allow you to implicitly or explicitly mark data in a response, so that the client can cache the response data, so that you can share the cached data for future requests, partially or entirely eliminates some interactions, increasing network efficiency. However, the information cached by the client increases the possibility of data inconsistency between the client and the server, thus reducing the reliability.

The advantage of the B/S architecture is that its deployment is very convenient, but it is not ideal in terms of user experience. To improve this situation, we introduced three new specifications to the original architecture: unified interfaces, hierarchical systems, and on-demand code.

3. unified interface

The core feature of the rest architecture style is to emphasize that there is a unified interface between components. This is manifested in the rest world, and all things on the network are abstracted as resources, while rest is to operate resources through a common linker interface. The benefit of this design is to ensure that the services provided by the system are decoupled, greatly simplifying the system, thus improving the system interaction and reusability. In addition, rest is optimized for common web conditions, so that the rest interface is designed to efficiently transfer large-granularity hypermedia data, this causes the rest interface to be not optimal for other architectures.

4. Hierarchical System

The addition of hierarchical system rules improves the independence between various layers, sets boundaries for the complexity of the entire system, and encapsulates legacy services to protect new servers from the influence of legacy clients, this improves the scalability of the system.

5. On-Demand code

Rest allows extension of client functions. For example, you can download and execute code in the form of an applet or script to expand the client functions. However, this also reduces visibility while improving system scalability. Therefore, it is only an optional constraint of rest.

Rest Standard Interface

Each resource has a corresponding URI. Different HTTP methods correspond to different operations on resources, such as get (read resource information), post (add resource), and put (update resource information), delete (delete resource ). Almost all computer languages can communicate with rest servers through the HTTP protocol.

Scenario:

  • A: http://www.nowamagic.net/articles
  • B: http://www.nowamagic.net/articles/{id}

Url a: Get method: displays all user information. At the same time, a POST method is provided to add users. The delte and put methods are generally not provided.

Url B: Get method: displays the current user information; put method: updates the user information; Delete method: deletes the user information.

Rest applications

Many of the popular Web 2.0 application api interfaces at Home and Abroad support the rest architecture style. For example: Sina Weibo open platform, Renren API, Google openid, Flickr, Twitter, eBay, Facebook, last. FM, Del. icio. us, Yahoo Search, Amazon S3, Amazon EC2, Digg, Microsoft Bing, friendfeed, PayPal, and Foursquare.

Brief Introduction to rest Architecture

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.