Restful web services 为的是在Web上工作的最好而创建的工具。Representational State Transfer (REST)是一种指定约束的设计风格,例如统一接口,它如果应用到webservice上将带来一些合适的特性,例如性能,可扩展性和可修改性,这些属性能够使services在Web上工作的最好。使用Rest设计风格,数据和功能都是被慎重考虑过的资源并且是通过Uniform Resource Identifiers (URIs) 来访问的。就像在Web上的链接。这些资源是按照一些简单并很好定义的的操作来采取行动的。Rest设计风格约束客户端/服务端统一用一种样式并且被设计成用一种无状态的通信协议,例如HTTP。在Rest的风格中,客户和服务端的交换代表资源用都在用标准的接口和协议。
The following principles encourage RESTful applications to be simple,lightweight, and fast:
如下规则鼓励Restful应用变的简单,轻重量,和迅速:
Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients. Resources are identified by URIs, which provide a global addressing space for resource and service discovery. SeeThe@PathAnnotation and URI Path Templatesfor more information.
资源通过URI定义:一个RESTful的 web service暴露一组资源用来鉴定和客户端交互的范围。资源通过URI来定义,这就提供了一个全球的地址空间来发现资源和服务。想要获得更多信息请查看The@PathAnnotation and URI Path Templates。
Uniform interface: Resources are manipulated using a fixed set of four create, read, update, delete operations:PUT,GET,POST, andDELETE.PUTcreates a new resource, which can be then deleted by usingDELETE.GET retrieves the current state of a resource in some representation.POST transfers a new state onto a resource. See Responding to HTTP Methods and Requestsfor more information.
统一接口:资源被一组4个已经被定义好的操作来操纵,create,read,update,delete:PUT,GET,POST,和DELETE。PUT创建一个新资源,可以通过DELETE删除。GET 用来获取一些表达式中的当前状态。POST 传递新的状态到一个资源。想要获得更多信息请查看 Responding to HTTP Methods and。
Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others. Metadata about the resource is available and used, for example, to control caching, detect transmission errors, negotiate the appropriate representation format, and perform authentication or access control. SeeResponding to HTTP Methods and RequestsandUsing Entity Providers to Map HTTP Response and Request
Entity Bodiesfor more information.
自我描述消息:资源和他们的表达式并不挂钩因此它们内容的存取可以通过各种形式,例如 HTML,XML 纯文本,PDF,JPEG,JSON或者其它的形式。关于资源的元数据是有效并使用过的,例如,对于控制缓存,探测查询错误,协商适当的数据格式,执行验证或是控制权限。想要获得更多信息请查看Responding to HTTP Methods and RequestsandUsing Entity Providers to Map HTTP Response and Request。
Stateful interactions through hyperlinks: Every interaction with a resource is stateless; that is, request messages are self-contained. Stateful interactions are based on the concept of explicit state transfer. Several techniques exist to exchange state, such as URI rewriting, cookies, and hidden form fields. State can be embedded in response messages to point to valid future states of the interaction. SeeUsing Entity Providers to Map HTTP Response and Request Entity Bodies and “Building URIs” in the JAX-RS Overview document for more information.
通过超链接实现状态交互:每次用资源进行交互都是无状态的,也就是,请求消息是独立的。状态交互是基于显式状态传输的概念。有一些技术是专门用来传输状态的,例如 URI 获取,cookies和隐藏表单,状态可以嵌套在返回消息中去指出有效的未来状态。想要获得更多信息请查看Using Entity Providers 去了解 HTTP返回和请求实体和“Building URIs” 在 JAX-RS 预览文件中获得更多的信息。