Restful web services 為的是在Web上工作的最好而創(chuàng)建的工具转晰。Representational State Transfer (REST)是一種指定約束的設(shè)計風格,例如統(tǒng)一接口,它如果應(yīng)用到webservice上將帶來一些合適的特性,例如性能叉信,可擴展性和可修改性,這些屬性能夠使services在Web上工作的最好艘希。使用Rest設(shè)計風格,數(shù)據(jù)和功能都是被慎重考慮過的資源并且是通過Uniform Resource Identifiers (URIs)?來訪問的硅急。就像在Web上的鏈接覆享。這些資源是按照一些簡單并很好定義的的操作來采取行動的。Rest設(shè)計風格約束客戶端/服務(wù)端統(tǒng)一用一種樣式并且被設(shè)計成用一種無狀態(tài)的通信協(xié)議营袜,例如HTTP撒顿。在Rest的風格中,客戶和服務(wù)端的交換代表資源用都在用標準的接口和協(xié)議荚板。
The following principles encourage RESTful applications to be simple,lightweight, and fast:
如下規(guī)則鼓勵Restful應(yīng)用變的簡單凤壁,輕重量,和迅速:
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來定義拧抖,這就提供了一個全球的地址空間來發(fā)現(xiàn)資源和服務(wù)。想要獲得更多信息請查看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.
統(tǒng)一接口:資源被一組4個已經(jīng)被定義好的操作來操縱唧席,create,read嘲驾,update淌哟,delete:PUT,GET,POST,和DELETE。PUT創(chuàng)建一個新資源辽故,可以通過DELETE刪除徒仓。GET 用來獲取一些表達式中的當前狀態(tài)。POST 傳遞新的狀態(tài)到一個資源誊垢。想要獲得更多信息請查看 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.
自我描述消息:資源和他們的表達式并不掛鉤因此它們內(nèi)容的存取可以通過各種形式症见,例如 HTML,XML 純文本狰晚,PDF筒饰,JPEG,JSON或者其它的形式壁晒。關(guān)于資源的元數(shù)據(jù)是有效并使用過的瓷们,例如,對于控制緩存秒咐,探測查詢錯誤谬晕,協(xié)商適當?shù)臄?shù)據(jù)格式,執(zhí)行驗證或是控制權(quán)限携取。想要獲得更多信息請查看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.
通過超鏈接實現(xiàn)狀態(tài)交互:每次用資源進行交互都是無狀態(tài)的,也就是雷滋,請求消息是獨立的不撑。狀態(tài)交互是基于顯式狀態(tài)傳輸?shù)母拍睢S幸恍┘夹g(shù)是專門用來傳輸狀態(tài)的晤斩,例如 URI 獲取焕檬,cookies和隱藏表單,狀態(tài)可以嵌套在返回消息中去指出有效的未來狀態(tài)澳泵。想要獲得更多信息請查看Using Entity Providers 去了解 HTTP返回和請求實體和“Building URIs” 在 JAX-RS 預(yù)覽文件中獲得更多的信息实愚。