web service —— rest


Web 服务可以非常复杂,这是因为 Web 服务开发常常会涉及到实现多种基础架构组件,比如 Web Services Description Language(WSDL)和 SOAP,而这些组件转而会绑定到各种其他的标准。为创建一个健壮的 Web 服务基础架构模型,每个提供 Web 服务解决方案的 Web 服务器都必须做出极大投入。从开发人员的角度看,掌握这个技术显得越来越复杂。但不要惧怕!REST 可救助大家。

RESTful Web 服务仅仅是 XML-over-HTTP 服务。一般的 Web 服务往往要求定义各种合约并需要在提供者和顾客之间进行协商,与之不同,RESTful 服务以一种简单的 XML 格式封装数据并在 HTTP 上传输,就如同对 Web 服务器发出的 Web 页面请求一样。

REST 更像是一种架构,而非一种实现或一个标准。REST 架构风格与 Web 资源相关,是由 Uniform Resource Indicator(URI)(例如, http://myweb.com/myresource)标识的一种表示。资源可以是任何持久的实体,包括 Order、Customer、 Employee 等。客户端通过此 URI 查询或更新这个资源,进而影响其具象状态更改。简言之,客户端程序可以使用各种 HTTP 方法通过 URI 访问、更新、添加或删除一个 Web 资源,并进而更改其具象状态。HTTP 方法包括 GETPOSTPUTDELETE

总之,REST 仅仅是一个规范,提供了一种标准方法供用户使用 Web 服务风格中的 HTTP 请求方法调用对 Web 资源的操作。REST 与 HTTP 紧密相关并利用了所有的 HTTP 特性,比如方法、头和类型。






What AreRESTful WebServices?

Representational State Transfer (REST) is a software application architecture modeled after the way data is represented, accessed, and modified on the web. In the REST architecture, data and functionality are considered resources, and these resources are accessed using Uniform Resource Identifiers (URIs), typically links on the web. The resources are acted upon by using a set of simple, well-deined operations. The REST architecture is fundamentally a client-server architecture, and is designed to use a stateless communication protocol, typically HTTP. In the REST architecture, clients and servers exchange representations of resources using a standardized interface and protocol. These principles encourages REST applications to be simple, lightweight, and have high performance.




RESTful web services are web applications built upon the REST architecture. They:

■ Expose resources (data and functionality) through web URIs.

■ Use the four main HTTP methods to create, retrieve, update, and delete resources.

RESTful web services typically map the four main HTTP methods to the so-called CRUD
actions: create, retrieve, update, and delete. The following table shows a mapping of HTTP

methods to these CRUD actions.

TABLE 1–1 HTTP Methods and their Corresponding CRUD Action


HTTPMethod
CRUDAction

GET Retrieve a resource.
POST Create a resource.
PUT Update a resource.
DELETE Delete a resource.


HowDoesJerseyFitIn?
Jersey is the open source reference implementation for Java API for RESTful Web Services
(JAX-RS, JSR 311). Jersey implements support for the annotations deined in JSR-311, making it
easy for developers to build RESTful web services with Java and the Java JVM. Jersey also adds
additional features not speciied by the JSR.
The Jersey 0.7 API's can be viewed at
https://jsr311.dev.java.net/nonav/releases/0.7/index.html
LearningMoreAboutRESTfulWebServices
The information in this guide focuses on learning about Jersey. If you are interested in learning
more about RESTful Web Services in general, here are a few links to get you started.
■ Representational State Transfer, from Wikipedia,
http://en.wikipedia.org/wiki/Representational_State_Transfer .
■ RESTful Web Services, by Leonard Richardson and Sam Ruby. Available from O'Reilly
Media at http://www.oreilly.com/catalog/9780596529260/ .
Some of the Jersey team members discuss topics out of the scope of this tutorial on their blogs. A
few are listed below:
■ Earthly Powers, by Paul Sandoz, at http://blogs.sun.com/sandoz/category/REST .
■ Marc Hadley's Blog, at http://weblogs.java.net/blog/mhadley/
■ Japod's Blog, by Jakub Podlesak, at http://blogs.sun.com/japod/category/REST .
You can always get the latest technology and information by visiting the Java Developer's
Network. The links are listed below:
■ Get the latest on JSR-311, the Java API's for RESTful Web Services (JAX-RS), at
(https://jsr311.dev.java.net/ ).
■ Get the latest on Jersey, the open source JAX-RS reference implementation, at
https://jersey.dev.java.net/ .


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值