REST

来源:互联网 发布:在淘宝上怎么分期付款 编辑:程序博客网 时间:2024/06/05 23:01

REST (Representational state transfer)

 

Representational state transfer是一种分布式系统的软件架构风格,是一种Web API的设计模式。

REST风格的架构一般是由客户端和服务器两部分组成,客户端向服务器端发送请求,服务器端处理请求并返回相应的响应。

 

约束:

1.         客户端-服务器

描述使用C/S架构

 

2.         无状态

服务器端不会存储用户上下文信息,每一个请求都回包含所有需要的信息,会话信息存储在客户端上

 

3.         缓存

客户端可以缓存服务器端的回复,但同时,服务器端也可以定义一个回复是否可以被缓存

 

4.         统一接口

The uniform interface between clients and servers, discussed below, simplifies and decouples the architecture, which enables each part to evolve independently.

 

5.         分层系统

A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way. Intermediary servers may improve system scalability by enabling load-balancing and by providing shared caches. They may also enforce security policies.

 

6.         按需代码

服务器可以临时向客户端传送代码去定制客户端的行为,例如包括Java appletJavaScript

 

 

关键原则:

1.         为所有“事物”定义IDURI

2.         将所有事物连接在一起

3.         使用标准方法

4.         资源多重表述

5.         无状态通信

 

(未完)