REST Web Services

RESTRepresentational State Transfer(表述性状态转移)的缩写。Client application transfers state with each resource representation. This is REST。

--Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.

它通过HTTP发送简单的消息实现SOA (Service Oriented Architecture),为一种体系结构风格。REST是SOAP的轻量替代品,面向资源,而不是面向操作。一个web service总是使用固定URI暴露一个资源,并且通过RPC调用HTTP的GET\POST\PUT\DELETE对于资源进行操作。

·         GET - 该操作返回已标识资源的状态表示。您可以通过大量的上下文要素来确定状态,例如谁正在提交请求、操作的参数(传入的参数如 HTTP 头或者查询字符串参数)和服务提供方维护的当前会话状态。其具有幂等性(多个相同的请求返回形同的结果)

·         POST - 该操作执行对已标识资源的一些特定于应用程序形式的更新。该操作行为完全依赖于实现它的服务。由该操作返回的数据也完全依赖于应用程序。举例来说,像 GET 操作一样,它可以返回一个状态表示,它还可以选择根本不返回任何数据。其不安全也不具有幂等性。

·         PUT - 该操作在已标识位置(URI)创建新资源。操作输入必须包括一个资源的状态表示。它完全依赖服务来创建基于这个状态表示的资源。具有幂等性。

·         DELETE - DELETE 操作销毁已标识位置(URI)的资源。具有幂等性。

REST Web Services Characteristics

  • Client-Server: a pull-based interaction style: consuming components pull representations.
  • Stateless: each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.
  • Cache: to improve network efficiency responses must be capable of being labeled as cacheable or non-cacheable.
  • Uniform interface: all resources are accessed with a generic interface (e.g., HTTP GET, POST, PUT, DELETE).
  • Named resources - the system is comprised of resources which are named using a URL.
  • Interconnected resource representations - the representations of the resources are interconnected using URLs, thereby enabling a client to progress from one state to another.
  • Layered components - intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.

设计REST式web service时,采用一下几个步骤:

·         决定资源ID及其描述性 URL。

·         为每个 URL 上的通信选择一种数据格式。

·         指定每个资源上的方法。

·         指定返回的数据和状态码。

·         无状态通信。REST要求状态保存在资源状态中,或者保存在client。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值