- 浏览: 89307 次
文章分类
最新评论
-
qq_27676511:
tomcat(jboss4.2) spring hibernate 项目移植到 jboss 5.1 -
lijunlong:
恩,晕
mysql 分区学习笔记 -
ytfei:
我是用xml配置的方式,没有遇到你说的问题,有时间我配置测试一 ...
tomcat(jboss4.2) spring hibernate 项目移植到 jboss 5.1 -
jiahch:
对了 我是从Tomcat 到 Jboss5.0
tomcat(jboss4.2) spring hibernate 项目移植到 jboss 5.1 -
jiahch:
解决 了 很多问题, 谢谢;
但是 还有 Hibernate实 ...
tomcat(jboss4.2) spring hibernate 项目移植到 jboss 5.1
原文链接:http://www.xfront.com/REST-Web-Services.html
Building Web Services the REST Way
Roger L. Costello
I will first provide a brief introduction to REST and then describe how to build Web services in the REST style.
What is REST?
REST is a term coined by Roy Fielding in his Ph.D. dissertation [1] to describe an architecture style of networked systems. REST is an acronym standing for Representational State Transfer.Why is it called Representational State Transfer?
The Web is comprised of resources. A resource is any item of interest. For example, the Boeing Aircraft Corp may define a 747 resource. Clients may access that resource with this URL:A representation of the resource is returned (e.g., Boeing747.html). The representation places the client application in a state . The result of the client traversing a hyperlink in Boeing747.html is another resource is accessed. The new representation places the client application into yet another state. Thus, the client application changes (transfer s) state with each resource representation --> Representational State Transfer! Here is Roy Fielding's explanation of the meaning of Representational State Transfer: "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://www.boeing.com/aircraft/747Motivation for REST
The motivation for REST was to capture the characteristics of the Web which made the Web successful. Subsequently these characteristics are being used to guide the evolution of the Web.REST - An Architectural Style, Not a Standard
REST is not a standard. You will not see the W3C putting out a REST specification. You will not see IBM or Microsoft or Sun selling a REST developer's toolkit. Why? Because REST is just an architectural style. You can't bottle up that style. You can only understand it, and design your Web services in that style. (Analogous to the client-server architectural style. There is no client-server standard.) While REST is not a standard, it does use standards:
- HTTP
- URL
- XML/HTML/GIF/JPEG/etc (Resource Representations)
- text/xml, text/html, image/gif, image/jpeg, etc (MIME Types)
The Classic REST System
The Web is a REST system! Many of those Web services that you have been using these many years - book-ordering services, search services, online dictionary services, etc - are REST-based Web services. Alas, you have been using REST, building REST services and you didn't even know it. REST is concerned with the "big picture" of the Web. It does not deal with implementation details (e.g., using Java servlets or CGI to implement a Web service). So let's look at an example of creating a Web service from the REST "big picture" perspective.Parts Depot Web Services
Parts Depot, Inc (fictitious company ) has deployed some web services to enable its customers to:Let's consider how each of these services are implemented in a RESTful fashion.
- get a list of parts
- get detailed information about a particular part
- submit a Purchase Order (PO)
Get Parts List
The web service makes available a URL to a parts list resource. For example, a client would use this URL to get the parts list:Note that "how" the web service generates the parts list is completely transparent to the client. All the client knows is that if he/she submits the above URL then a document containing the list of parts is returned. Since the implementation is transparent to clients, Parts Depot is free to modify the underlying implementation of this resource without impacting clients. This is loose coupling .http://www.parts-depot.com/partsHere's the document that the client receives:
[Assume that through content negotiation the service determined that the client wants the representation as XML (for machine-to-machine processing).] Note that the parts list has links to get detailed info about each part. This is a key feature of REST. The client transfers from one state to the next by examining and choosing from among the alternative URLs in the response document.<?xml version="1.0"?> <p:Parts xmlns:p="http://www.parts-depot.com" xmlns:xlink="http://www.w3.org/1999/xlink"> <Part id="00345" xlink:href="http://www.parts-depot.com/parts/00345"/> <Part id="00346" xlink:href="http://www.parts-depot.com/parts/00346"/> <Part id="00347" xlink:href="http://www.parts-depot.com/parts/00347"/> <Part id="00348" xlink:href="http://www.parts-depot.com/parts/00348"/> </p:Parts>Get Detailed Part Data
The web service makes available a URL to each part resource. Example, here's how a client requests part 00345:Here's the document that the client receives:http://www.parts-depot.com/parts/00345Again observe how this data is linked to still more data - the specification for this part may be found by traversing the hyperlink. Each response document allows the client to drill down to get more detailed information.<?xml version="1.0"?> <p:Part xmlns:p="http://www.parts-depot.com" xmlns:xlink="http://www.w3.org/1999/xlink"> <Part-ID>00345</Part-ID> <Name>Widget-A</Name> <Description>This part is used within the frap assembly</Description> <Specification xlink:href="http://www.parts-depot.com/parts/00345/specification"/> <UnitCost currency="USD">0.10</UnitCost> <Quantity>10</Quantity> </p:Part>Submit PO
The web service makes available a URL to submit a PO. The client creates a PO instance document which conforms to the PO schema that Parts Depot has designed (and publicized in a WSDL document). The client submits PO.xml as the payload of an HTTP POST.
The PO service responds to the HTTP POST with a URL to the submitted PO. Thus, the client can retrieve the PO any time thereafter (to update/edit it). The PO has become a piece of information which is shared between the client and the server. The shared information (PO) is given an address (URL) by the server and is exposed as a Web service.
Logical URLs versus Physical URLs
A resource is a conceptual entity. A representation is a concrete manifestation of the resource. This URL:
http://www.parts-depot.com/parts/00345
is a logical URL, not a physical URL. Thus, there doesn't need to be, for example, a static HTML page for each part. In fact, if there were a million parts then a million static HTML pages would not be a very attractive design. [Implementation detail: Parts Depot could implement the service that gets detailed data about a particular part by employing a Java Servlet which parses the string after the host name, uses the part number to query the parts database, formulate the query results as XML, and then return the XML as the payload of the HTTP response.] As a matter of style URLs should not reveal the implementation technique used. You need to be free to change your implementation without impacting clients or having misleading URLs.
REST Web Services Characteristics
Here are the characteristics of REST:
- 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.
Principles of REST Web Service Design
1. The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services. Above we saw some examples of resources: parts list, detailed part data, purchase order.
2. Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this:
Note the verb, getPart. Instead, use a noun:http://www.parts-depot.com/parts/getPart?id=00345http://www.parts-depot.com/parts/00345
3. Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE. 4. All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource. 5. No man/woman is an island. Likewise, no representation should be an island. In other words, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information. 6. Design to reveal data gradually. Don't reveal everything in a single response document. Provide hyperlinks to obtain more details. 7. Specify the format of response data using a schema (DTD, W3C Schema, RelaxNG, or Schematron). For those services that require a POST or PUT to it, also provide a schema to specify the format of the response. 8. Describe how your services are to be invoked using either a WSDL document, or simply an HTML document.
Summary
This article described REST as an architectural style. In fact, it's the architectural style of the Web. REST describes what makes the Web work well. Adhering to the REST principles will make your services work well in the context of the Web. In a future article I will write about the evolution of the Web using the REST principles.
Acknowledgement
Thanks to Robert Leftwich and Philip Eskelin for their very helpful comments in creating this document.
Translations of this Article
Jason Fragoso translated this article into Belorussian: http://www.movavi.com/opensource/REST-web-services-be
References
[1] http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
发表评论
-
功能和数据权限系统设计
2011-06-02 20:33 1334RBAC权限系统能很简单的应用于功能权限系统(或者可以称作控制 ... -
android,java,ndk,c++ iphone 之争
2011-04-26 18:06 1719http://coolshell.cn/articles ... -
技术跟踪
2011-04-03 11:37 0TinyMCE 开源文本编辑器 -
eucalyptus笔记
2011-03-28 22:40 0In MANAGED mode, Eucalyptus wil ... -
vmware 扩展空间
2011-03-15 16:49 753vmware-vdiskmanager -x l2GB D:\ ... -
px pt dpi 的关系
2011-03-15 15:05 1357px:pixel,像素,屏幕上显示的最小单位,用于网页设计,直 ... -
正则表达式笔记(二)
2011-03-03 10:27 1014转:http://www.regular-expressio ... -
正则表达式笔记(一)
2011-03-03 10:26 1001参考:http://blog.csdn.net/axwolfe ... -
利用SSD优化Oracle存储
2011-03-01 17:54 1987转自:http://withjava.iteye. ... -
转:基于第四层交换技术的负载均衡
2011-02-27 20:40 961基于第四层交换技术 ... -
云计算学习历程
2011-01-10 17:50 0http://labs.google.com/papers/m ... -
什么是raid
2011-01-02 23:30 735参考: http://www1.lob.cn/n291c22 ... -
七层交换技术
2011-01-02 20:03 8222层交换 基于MAC地址 3层交换 基于IP,MAC地址(路 ... -
页面缓存参数
2010-11-21 22:02 1266参考:http://xingba.iteye.co ... -
用APACHE ABD压力测试
2010-10-29 21:35 620http://hi.baidu.com/youdianweid ... -
关于 samba
2010-10-27 22:46 691ubuntu 下安装 apt-get install sa ... -
大型视频网站架构 参考网站
2010-09-27 18:01 1024http://zhidao.baidu.com/questio ... -
sendmail 配置
2010-08-18 22:08 899http://www.cnblogs.com/fjsbf/ar ... -
windows下下载的ubuntu ISO 安裝方法
2010-07-20 21:59 3291windows下下载的ubuntu ISO 安裝方法 1.安 ... -
加密技术的选择
2009-08-22 23:19 832数据加密标准(DES)是 ...
相关推荐
Flask Building Python Web Services 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Completely up-to-date to reflect the newest and most widely used Android SDKs, The Android Developer’s Cookbook is the essential resource for developers building apps for any Android device, from ...
Programming Collective Intelligence: Building Smart Web 2.0 Applications 英文epub版本
REST is an architectural style that tackles the challenges of building scalable web services. In today’s connected world, APIs have taken a central role on the web. APIs provide the fabric through ...
Building RESTful Web Services with Go:Initially, SOAP-based web services became more popular with XML. Then, since 2012,REST picked up the pace and gulped SOAP in whole. The rise of a new generation ...
Chapter 8: Building Node.js REST API Servers with Express.js and Hapi Chapter 9: Real-Time Apps with WebSocket, Socket.IO, and DerbyJS Chapter 10: Getting Node.js Apps Production Ready Chapter 11: ...
本书《*** MVC 4 and the Web API: Building a REST Service from Start to Finish》专注于如何利用*** MVC 4框架结合Web API构建世界级的REST服务。该书深入详细地介绍了如何使用*** MVC 4和Web API构建先进的REST...
REST is an architectural style that tackles the challenges of building scalable web services and in today's connected world, APIs have taken a central role on the web. APIs provide the fabric through ...
ASP.NET Core Application Development: Building an application in four sprints (Developer Reference) By: James Chambers; David Paquette; Simon Timms Publisher: Microsoft Press Active Server Pages ASP...
这本书《Learning to Program with MATLAB:Building GUI Tools》主要讲述了如何使用MATLAB来构建图形用户界面(GUI)工具。 GUI,即图形用户界面,是一种用户与计算机软件交互的界面方式,用户通过图形元素,如...
Chapter 16: Building REST APIs with Django REST Framework (NEW) Chapter 17: Consuming REST APIs Chapter 18: Tradeoffs of Replacing Core Components Chapter 19: Working With the Django Admin Chapter 20:...
《Vue.js Up & Running: Building Accessible and Performant Web Apps》是一本专注于使用Vue.js框架构建可访问且高性能Web应用的指南。Vue.js是目前非常流行的前端JavaScript框架,以其轻量级、易学易用和灵活性...
Building RESTful Web services with Go 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
It serves the purpose of building great web services in the RESTful architecture. This book will show you the best tools you can use to build your own web services. Learn how to develop RESTful APIs ...
Whether you’re sharing data between two internal systems or building an API so users can access their data, this practical book provides everything you need to build web service APIs with ...
Chapter 10: Getting Started with Web Services Chapter 11: Creating a Universal App Chapter 12: Deploying Your iOS App Appendix: Answers to Exercises Book Details Title: Beginning iOS Programming: ...