Rest architecture style 2: CRUD (zz)

Source: Internet
Author: User
In the previous section, we learned from two examples: Rest Status indicates the transfer taste, but it should be pointed out that these two examples are just simple resource acquisition. Rest Resources are the core and there is no service concept, which is indeed doubtful. Rest Can it be like Orb Or SOA Does it support complex applications? Before answering this question, let's leave now Rest To focus on Relational Database-based 3 Layer architecture.

The business logic layer usually provides a number of functional interfaces (defined inIorderserviceTo access the database through the data access layer. We know that relational databases only defineCrud (create, read, update, delete)The four standard data operations correspondInsert/select/update/deleteFour TypesSQLStatement. Experience tells us that relational database operations on several tables are sufficient to support a variety of complex business logic, because all business functions will eventually be mapped to the database.CrudFour standard operations. The following interesting triangle can help us understand this problem:

The triangle in the figure represents the data type, operation, and instance respectively. Think of them as adjustable buttons. the business logic layer defines a small number of service instances and places a large number of operations under the service instances, the image is like "a small door with many things installed in it", while the database provides a large number of data instances andCrudThere are four standard operations, which can be called "many doors, each door containing a few things ".

Resource-centric Rest Similar to data-centric relational databases. Data and resources are essentially State operations Crud One less is not acceptable. One more is redundant. Therefore, Rest Also used Crud The four standard operations correspond HTTP Protocol Post/get/Put/delete Method. Although HTTP supports Post/get/Put/delete Other methods such as head can be used as a useful supplement, but should not affect the purity of the rest model. In the previous section, we can see that Rest A style application is like a state machine. here we can see that it is like a database. Press Rest Resources defined by the method ( URL ) And the corresponding operations are like the following ( It is worth noting that URL The meaning of "Uniform Resource positioning operator" can be seen that its versatility, which is also Rest Advantages of resource Representation ):

RestPerfect CombinationHTTPProtocol, so it is easier to seamlessly access the internet. In addition, some people mentioned "The number of web pages exposed by a website can be used as an indicator to measure its contribution to the Internet ."RestMode-specific servicesSOAIt is more friendly to the Internet.However, what style of architecture should be used depends on the characteristics of the application itself. Generally, for applications that provide and manage data, and want Seo applications to be applicable to the REST style, this includes most web applications. Applications that focus on Computing and business logic and emphasize security are not suitable for rest. However, service-oriented thinking should be avoided without prior analysis. Sometimes the rest architecture that appropriately uses the State expression transfer mode can not only implement business logic, but also provide better scalability, as mentioned in the previous section, the psychological testing service is the same as Google search. The value of rest is that we have an extra perspective when designing the architecture. The so-called "Vision determines the world ".

Cache

Because Rest Of URL Indicates the features of resources and stateless services Cache The mechanism becomes abnormal and simple, And HTTP Directly supported in the Protocol. Server response can be passed through Cache-control: Max-age , Expires specifies the resource cache time; you can also Last-modified The parameter indicates the last modification time of the resource. The client request can contain If-modified-since Parameter. If the resource has not expired, the server only needs to return 304 not modified In this way, you can avoid repeated operations on the server and save network bandwidth; Etag Parameters are also common Cache Control parameters can solve the problem that the last-modified time precision is not enough. In addition, HTTP The Protocol is also Proxy The Mechanism has direct support, and Cache In applications that require high performance, you can deploy a number Cache Purpose Caching Proxy Server improves system throughput .

Summary

Summary Rest Key points: 1. URL Resource ; 2. Crud Operation ; 3. Status indicates transfer. For stateless services, HTTP Status Code, Cache Control, Proxy And so on. Rest The key is to understand the resource-centric model. This article is my contact Rest Some experiences and summaries in less than a year are well aware Rest you must continue to work hard to master and apply the service!

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.