官术网_书友最值得收藏!

REST principles

REST is a software architecture approach for creating scalable web services. The term REST was coined by Roy Fielding in his PhD dissertation, and revolves around a number of principles. These principles underpin the architecture of RESTful web services and are described in the following sections.

Uniform interface

At the core of REST are resources, and resources are identified using Uniform Resource Identifiers (URIs). Conceptually, resources are separate from their representation (that is, the format in which they are provided to clients). REST does not mandate any specific format, but typically includes XML and JSON (which will be discussed in Chapter 4, Data Representation).

In addition, resource representations are self-descriptive. In more concrete terms, this means that sufficient information must be returned for the successful processing of responses.

Another distinctive property of REST is that clients interact entirely through hypermedia, which is dynamically provided by the application servers. Apart from endpoints, clients need no prior knowledge of how to interact with a RESTful service. This constraint is referred to as Hypermedia as the Engine of Application State (HATEOAS).

Client-Server

The client-server model that REST embraces enables the separation of client concerns, such as user interaction or user state management, from that of server concerns such as data storage and scalability.

This decoupling ensures that, provided an interface that is agreed upon, the development of client and server can be done independently. It also helps reduce complexity and improve the effectiveness of performance tuning.

Stateless

REST advocates statelessness. No client state is stored on the server. All the information needed to perform operations is contained in the requests (as part of the URL, request body, or as HTTP headers).

Cacheable

RESTful web services must provide caching capabilities. Servers can indicate how and for how long to cache responses. Clients can use cached responses instead of contacting the server.

Tip

This principle has significant advantages for scalability. Caching techniques will be discussed in Chapter 6, Performance.

Since REST typically leverages HTTP, it inherits all the caching properties that HTTP offers.

Layered system

Given the style of communication between clients and servers, clients are not aware of which specific server they are interacting with. This property allows the introduction of intermediate servers that can, for example, handle security or offer load-balancing capabilities. These architectural concepts are discussed in more detail in Chapter 10, Scaling a RESTful Web Service.

Code on demand

Even though it's part of the REST architecture, this principal is optional. Servers can temporarily extend the functionality of clients by transferring executable code. For example, JavaScript can be provided to web-based clients to customize functionality.

For a service to be considered RESTful, it should abide by the preceding principles.

主站蜘蛛池模板: 龙山县| 临邑县| 京山县| 辰溪县| 东源县| 靖宇县| 鸡泽县| 盐源县| 铁岭市| 东兴市| 峨边| 泉州市| 宝丰县| 白河县| 榆中县| 昌宁县| 策勒县| 四平市| 满洲里市| 蓝山县| 梁平县| 比如县| 合江县| 柳州市| 繁峙县| 邮箱| 布尔津县| 麦盖提县| 涿鹿县| 手游| 德格县| 都昌县| 武宁县| 宁海县| 澜沧| 宁城县| 中超| 珠海市| 武宁县| 曲阳县| 府谷县|