Sd2.0 rest and resource-oriented web development

Source: Internet
Author: User

Sd2.0 rest and resource-oriented web development
What is web?
From a technical point of view, the first is Uri, which identifies resources; the second is HTTP protocol, which operates resources; the third is hypertext, which describes the resource status.
What is a Web application?
The above three technologies are used first, and then run in the Internet environment, instead of the LAN or Intranet environment.
Web applications in the broad sense include all applications that use the above three technologies. in the narrow sense, web applications only refer to applications in browsersProgram.
What is architecture style?
An architectural style represents the constraints that a group of runtime environments impose on architecture design. It is like a class or an interface. What about a specific architecture, it is an example of an architectural style.
Two keywords: Architecture Design and runtime environment. This is similar to the design pattern. Each pattern has its applicable scenarios.

Common distributed application architecture
The first type is distributed objects, including CORBA, DCOM, and remoting.
The second type is remote process calling (RPC), such as soap and JSON.
The third type is declarative state transfer (rest for short ).

What is rest?
Rest is short for representitional state transfer. Rest is an architectural style. It comes from Roy Fielding's doctoral thesis "architecture style and network-based software architecture design". Rest is the most successful architectural style in the world. The main success story is web.
Can view the Wikipedia for a rough look: http://zh.wikipedia.org/zh/REST

What are the architectural constraints of the rest architecture style?
The first architecture constraint is the client server. Communication can only be initiated by the client in the form of a request response.
The second architecture constraint is stateless. The client is responsible for maintaining the communication session status, and the server is responsible for maintaining other States except the session status.
The third architecture constraints cache. The response content can be buffered somewhere in the communication chain to improve efficiency.
The fourth unified interface requires a unified interface between communication components to improve interaction visibility. In this way, the intermediate components are very clear about the request semantics and facilitate caching or implementing security policies.
The fifth architecture constraint is a layered system. By limiting the behavior of components, the architecture is divided into several levels of layers, and each component can see the adjacent layers that interact with it.
The last architecture constraint is on-demandCodeBy downloading and executing code in the form of an applet or script, you can expand the client functions.

Five Keywords of rest
Resources
Resource Description
Status Transfer
Unified Interface
Hyper Text drive

What is a resource?
Resources are a way to look at servers. servers are considered to be composed of many discrete resources. This way of looking at servers is obviously different from distributed objects. Distributed objects are considered as an object, each object contains calling methods. Rest is considered a lot of discrete resources. Resources are an abstract concept that can be named by the server, and resources are an abstract concept, you may have understood that the resource is only a server file or a table, but the resource is abstract. The resource is characterized by nouns, APIs in resource object-oriented programming are exposed to external interfaces. Resources are identified by one or more Uris. Uris are the nouns of resources and the addresses of resources on the web, multiple Uris are allowed to identify the same resource. customers interested in the resource can interact with the resource through Uris.

What is a resource expression?
It is a description of the status of a resource at a specific time. The resource expression can be transferred between the customer and the server. The resource expression can be in multiple formats, the most common is HTML/XML/JSON plain text, which can be determined by the negotiation mechanism. Generally, the expressions in different directions are in different formats. The expressions from the server to the client and from the client to the server are different.

What is status transfer?
Status transfer refers to the expression of resource status transferred between the client and the server. It indirectly achieves the purpose of resource operation through the expression of resource transfer and operation, in the rest architecture style, operations on resources are carried out indirectly. Operations on resources are carried out indirectly through resource expressions, however, objects or methods exposed on the server are directly operated on distributed objects and IPC.

What is a unified interface?
A unified interface is used to perform various operations on resources, and only one group of limited operations can be performed on each resource. Unlike distributed objects, HTTP defines a unified interface for operating resources, including the following content, the first is eight standard methods, including get, post, put, delete V, and head. The last four methods are rarely used. The first four methods are basically used. You can customize new information when developing HTTP header information. There is also a part of HTTP response status code, which has a lot of code in the protocol and can be customized during development. The semantics of the unified interface operation must be fully expressed by the part before the HTTP message body. If the operation or message body does not meet the unified interface requirements, unified requirements must be fully expressed before the HTTP message body.

What is Hyper Text-driven? (Not yet understood ...)
Hyper Text drives first regard Web applications as a finite state machine composed of many States. These States include both the maintenance of the client and the resource status. The entire state is combined with the application status, resources are correlated through hyperlinks. Hyperlinks represent the relationship between resources and executable State migration. Hypermedia not only contains data, but also contains State Migration semantics. The super media engine is used to drive web application state migration. The super media exposes the resources provided by the server through the super media, and the resources provided by the server are discovered by the client by parsing the super media, instead of being defined.

What are the main features of the rest architecture?
1. addressable
Rest is composed of many resources. Each resource has at least one Uri, representing an address.
2. Stateless
The status is completely maintained by the client.
3. Connectivity
A rest-style architecture must ensure the connectivity between resources, connect to each other through hyperlinks, and design a rest architecture. There are a large number of isolated resources, which are completely not connected to each other. This architecture design is very unsuccessful, be sure to connect through a hyperlink.
4. unified interface
Unified Interface
5. Resource-Oriented
The rest architecture is designed with resources as the core. The first important thing is how to implement these resources.
6. Hypertext-driven
Use hypertext to drive web application migration

The above features are combined to achieve the final effect, that is, loose coupling, the rest architecture style is always loose, and the distributed architecture is tight.

Some misunderstandings about HTTP
1. the browser only supports the get/POST method, and the HTML form only supports the get/POST method.
You can simulate a put request by attaching parameters. After sending the request to the server, you can interpret the request as a put request. The XMLHTTPRequest object supports four methods, such as post.
2. Over-using the get method, add a question mark after it, and use the get method to send any operation
There are two main disadvantages: the first one is that the sensitive information is not safe enough in the URL. The second disadvantage is that it is very vulnerable to Crawler attacks. Make a website crawler to make a link to the website. For example, if you do something to delete the server and the database contains a user data, after your website is crawled, you will find that there is a lot of user data in your database.
3. Excessive use of the post Method
The most typical is the RPC-style call protocol such as soap. It does not use other methods and takes too many responsibilities. It does not take full advantage of HTTP and does not use HTTP status code, the advantages of HTTP are not fully utilized at all.
4. misunderstanding that HTTP is an RPC Style

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.