這兩天學習REST及其java實現框架Restlet.具象狀態傳輸(Representational state transfer,REST)是設計基于命名資源而非消息的松耦合應用程序的一種風格。構建 RESTful 應用程序的最困難的部分在于確定要公開哪些資源.個人認為它跟DDD聯系的很緊密,特別是REST中的“資源”,我個人理解它就是從領域模型中的模型而來的。
我們先來看一下restlet core api吧:
Overview of a Restlet architecture
Here is a diagram illustrating how the API composes components, connectors, virtual host and applications. Applications are in turncomposed of resources.

用白說來講就是:Application通過Router 將某個URI與Resource綁定在一定,而一個componet可能含有多個Application,
還有Representation 這個類其實也很重要。Representation entity:Restlet中全部的接受和返回對象都Representation類的子類。
如在WEB APP中經常需要從一個FORM中拿到其Representation(getWebRepresentation()
)或組裝成一個Representation
Form(Representation webForm)
,以便客戶端與服務器進行交互。我們知道REST是以資源為中心的,一個URI就代表了對這個資源的CURD操作。@Path這個注解提明了
哪個操作是由該資源的那個方法來實現的如:
@POST
@Path("add")
public String addStudent(Representation entity) {
}
...
@DELETE
@Path("delete/{id}")
public String deleteStudent(@PathParam("id") int id) {
int status = ResourceHelper.deleteStudent(id);
return String.valueOf(status);
}
representation package overriew:
Restlet 對表現層的技術支持也就是通來representation這個類來實現的,representation
Restlet并沒有你Setvlet API那樣有自已的JSP作表現的技術,它是通過將這三種模板技術整合起來而已如 : XSLT, FreeMarker and Apache Velocity
The org.restlet.representation package contains common representation data elements. Here is a hierarchy diagram with the core Representation classes:
Overview Representation package

當然restlve只是提供了一個入口,碰到要對數據庫進行CURD操作時,基具體實現還是由JDBC等技術來實現.
posted on 2012-05-24 12:19
jimmy2009 閱讀(389)
評論(0) 編輯 收藏 所屬分類:
系統架構