appendix C

来源:互联网 发布:碳纤维地暖 知乎 编辑:程序博客网 时间:2024/06/06 10:02

This appendix will give you a minimal REST background that will help you understand the main concepts at the core of the Restlet Framework. Understanding REST is key to using the Restlet Framework because it’s the official architecture style of the web and because the Restlet API is a direct mapping of REST and HTTP concepts to Java. We’ll  lso discuss the relationship between REST and HTTP, comparing it with the historical RPC-like alternatives such as SOAP.

该附录将简单介绍Rest 背景,它将有助于你理解Restlet 框架核心概念。使用Restlet框架是因为它是其网络架构的具体实现,同时Restlet API 建立起Rest 和 HTTP 概念与java类的直接映射,这有助于理解Rest。我们也会讨论Rest 与 HTTP之间的关系,并和过去 RPC风格架构(如:SOAP)进行比较。

C.1 Supporting all web features with REST

使用Rest支持所有网络特性

Billions of people use the web in one form or another. Millions of developers create web applications. Yet only a small number of them have heard about REST, which defines the architectural style of the web. REST was created by Roy T. Fielding, the primary architect of HTTP 1.1, the backbone protocol of the web.

数十亿人以各种形式使用网络。数百万开发人员开发网络应用,然而他们中只有少数人听说过REST,REST是一种网络架构风格,由Roy T.Fielding提出,他本人是HTTP 1.1主要是架构者,是网络协议的骨干人员。

REST is the acronym for REpresentational State Transfer. It’s a set of principles that, when correctly applied, helps in building software architectures and applications that benefit from all the qualities of the web. Those qualities are numerous and include greater scalability, efficient network use, and independent evolution of clients and servers (also called loose coupling).

REST 是表述性状态传输(representational state transfer)的缩写。它包含一套原则,当正确的使用,将有助于建立受益所有网络特性的软件架构和应用这些特性有很多,包括更高的可扩展性,高效的网络使用客户端和服务器独立演进(也称为松耦合

Now, would you build a Gothic church or an art deco hotel without knowing about the Gothic or art deco architectural styles? Certainly not! The same is true for the web; you  houldn’t build web applications without knowing about the architectural style of the web. By understanding the principles defined by REST and applying them in your evelopment, you’ll be able to create distributed systems with highly valuable properties such as scalability, loose coupling, performance, and simplicity.

现在,你能在不了解哥特式或者艺术装饰架构风格下建立起一个哥特式教堂或者艺术装饰酒店吗?当然不能,对于网络同样如此;在你不了解网络架构风格时,你是不能构建web应用的。通过理解REST定义的原则并在你的开发中使用他们,你才会创建具有诸如可扩展性、松耦合、高性能、简单等高价值特性的分布式系统。

 This section gives you the big picture of the web—its increasing role as the center of our information system and its impact on all types of applications and platforms like obile devices. Next we discuss REST and its architecture elements and explain its relationship to the HTTP protocol.

本节为您提供了网络图貌——在信息系统中越来越大的作用 和 它对应用和平台的影响(如obile设备接下来我们讨论REST和它的架构元素解释它与HTTP协议的关系

C.1.1 The all-embracing web

闭环的网络

Everybody knows about the Web 1.0, the web of hyperlinked text documents built on top of the internet, where web browsers and web servers are kings using the HTTP protocol to exchange those documents.

大家知道的Web1.0,是建立在互联网之上的超链接文本文件网络,Web浏览器和Web服务器使用HTTP协议来交换这些文件

 Later the AJAX technique offered a way to asynchronously send HTTP calls from web pages, clearing the path for Web 2.0 and the Rich Internet Applications that were more complex, reactive, and more social. This new way of using the web gave rise to a whole new range of frameworks, such as jQuery and Google Web Toolkit, that tried to facilitate the development of dynamic, JavaScript-based applications hosted in web browsers.

后来的AJAX技术提供了一种异步发送HTTP请求的方式来访问网页,为Web 2.0 和更复杂、更互动、更社交化的富互联网应用清除了道路这种新的使用网络方式给人们带来一些全新的框架,如jQuery和Web工具包,它们促进了动态开发的发展、以及托管Web浏览器基于JavaScript的应用

Many efforts were made to realize Tim Berners-Lee’s vision of a web of machines talking to each other on behalf of their human owners in a more meaningful way. This is the Semantic Web, often called Web 3.0, that we cover in more detail in chapter 10. This led to the Linked Data movement and the creation of a web of hyperdata, mostly parallel to the previous forms of the web.

经过许多努力去实现蒂姆·伯纳斯 - 关于以人机交互为代表的一种更有意义的网络愿景。这就是语义Web,通常被称为Web 3.0,我们在第10章更详细地介绍这将引领关联数据的移动和建立一个hyperdata,大多是平行于先前Web形式的Web

Cloud computing introduced a radical change in the way we build and provision applications at web scale. Making extensive use of web APIs, as exemplified by Amazon Web Services, cloud computing drives significant cost reductions, simplifies maintenance, and allows organizations to be much more reactive and focused than when managing the infrastructure themselves.

计算带来了 一个我们创建和提供Web 应用方式根本性的转变例如亚马逊Web服务广泛使用WebAPIs,云计算的驱动相比于自身管理基础设施,降低运维成本、简化维护并能让组织更具交互性和聚焦

The latest wave has been led by mobile phones and tablets becoming smarter, touting fully featured web access, and offering new interaction experiences thanks to native apps and marketplaces. In countries where computers aren’t widespread, mobile phones have even become the primary way of accessing the web. Even though the web browser isn’t always at center stage, web standards such as HTTP and JSON connect those applications, often using back ends in the cloud to store and share data and do heavy processing.

手机和平板电脑已经成为更智能、功能齐全的网络接入方式,并引领着最新潮流。它们为原生应用和网络市场提供了新的交互体验,在电脑不普及的国家,手机更是主要的网络访问方式。即使Web 浏览器不处于舞台中央,但像HTTP、JSON这样的Web标准连接到那么应用通常使用后端的云进行数据存储和交互的繁重处理。

We’re now seeing the rise of the internet of things, also called the web of things, making the web more present in our daily lives and more transparent at the same time, entering our home in new forms such as connected body scales, thermostats, or power regulators. Hypermedia isn’t always the best UI, and HTML 5 might not be the answer to all our interaction needs, but the web is still at work to exchange information via web APIs and allow more consistent experiences across all those machines.

我们现在看到在互联网中兴起的事物,也网络事物,它们使网络存在于我们的日常生活中,同时也更加透明化。它们以新的形式走进我们的家,例如连接人体秤、温控器、或者权力监管。超媒体并不总是最好的用户界面HTML5可能并不满足我们的交互需求但Web仍通过Web APIs交换信息进行工作,并允许在所有这些设备上有一致的体验。

Adapting to all those types of webs, as visualized in figure C.1, represents a big challenge when designing your web applications. They need to scale and adapt to various environments such as small screens, stay manageable, and evolve quickly to address new market trends or user needs.

图C.1中展示了这些不同的Web 类型,当设计你的Web应用时适应他们将是一大挑战他们需要能够扩展和适应各种环境小屏幕,持续管理快速开发满足新的市场趋势或用户需求

                                             

C.1.2 How REST explains the architecture elements of the web

REST如何诠释Web架构元素

One of the masterminds behind the web is Roy T. Fielding. In 1994 he started working as a doctorate student at University of California Irvine, contributing to the specification of several web standards and rationalizing the design choices that were made.

Roy T.Fielding是Web 灵魂人物之一。1994年,他作为加利福尼亚大学欧文分校博士学位的学生开始参与多个Web标准的规范化和决策合理化的设计选择工作。

In 2000, he published a PhD thesis under the rather abstract title Architectural Styles and the Design of Network-based Software Architectures, which included a chapter with an even more cryptic title: “REpresentational State Transfer (REST).” [12] This thesis remained confidential for a few years, but as REST was constantly promoted and interest in it grew quickly, the thesis became widely read and is still debated today.

在2000年,他出版了一篇标题相当抽象的博士论文:基于网络的软件架构和设计,其中一个章节提出了一个更新颖的名词:“表述性状态传输(REST)”[12]   论文虽然封存了几年,但对REST的提及不断促进对它的兴趣的迅速增长,论文至今仍被广泛阅读和讨论。

Why so much interest in this text that’s rather abstract and hard to digest? Well, REST explains the architecture of the web so well that it illuminates many features and design choices that were made by the builders of the web. It contains a blueprint that all web applications should follow.

为什么对一个十分抽象又难以消化的文本如此感兴趣呢? 是的,REST 很好的解释了网络架构,它为网络开发者提供了许多特性和设计选择。它包含了所有Web应用程序应遵循的蓝图。

The thesis starts with a general discussion of software architectures, continuing with specifics of network-based application architectures. Fielding then proposes a classification of architectural styles such as pipe and filter, client-server, layered systems, remote sessions, virtual machines, code on demand, and distributed objects. Building architects could have the same discussion about building architectural styles such as Roman or Gothic.

 论文的开始对软件架构进行了一般性讨论,然后继续介绍了基于网络的应用程序架构细节。Fielding 提出了架构风格的分类,如管道和过滤器,客户端 - 服务器,分层系统,远程会议,虚拟机,代码点播,分布式对象。大厦的建筑师可能有相同的如罗马式或哥特式建筑风格建设的讨论。

 Fielding describes software architectures as a configuration of architectural elements, which are, in the case of REST, components, connectors, resources,  representations, and a few data elements. In the following sections we take a look at the higher-level architectural elements, because this provides a good way to start comprehending REST and Restlet.

  Fielding 通过架构元素,REST的情况下,包含组件、连接资源,表述和一些数据元素的配置来介绍软件架构在下面的章节我们一起来看看这些更高级别的架构元素因为这提供了一个很好的方式去理解RESTRestlet

RESOURCES

资源

One important characteristic of those resources is that they’re linked together by embedded hyperlinks in HTML documents or URI references in feeds pointing to recent blog posts. In exactly the way it was envisioned and named by its creator Tim Berners-Lee, the web is a distributed set of resources that can be navigated and discovered dynamically.

这些资源一个重要特点是,他们通过嵌入在HTML文档中超链接或者通过URI引用最近的博客文章将资源联系在一起。它以创始人Tim Berners=Lee名字命名,Web是一个可以导航和发现的分布式资源集合。

                                                 

To allow users to retrieve them from anywhere in the world, each resource is given a unique name called a Uniform Resource Identifier or URI (for example, http://www.paris.fr/weather), enabling identification and remote access on the internet.

为了用户能够从世界任何地方获取它们,每一个资源都有一个唯一的名称来标识和访问,名称被称为统一资源标识或者URI(如, http://www.paris.fr/weather).

As shown in figure C.3, a resource can expose its state via representations containing both metadata (such as size, media type, or character set) and content (binary image or text document). The representation of a confirmation of purchase on eBay could be an HTML document; for a wedding picture it could be a JPEG binary stream; for a contact in an address book web service it could be an XML fragment; and so on.

图C.3所示,资源通过表述来暴露其状态,表述包含元数据(如:尺寸、介质类型、或字符集)和内容(二进制图像或文本文件)。在eBay上购买确认阶段的表述可能是一个HTML文档;婚礼图片可能是一个JPEG 二进制流;在地址簿的Web服务中一个联系人可能是一块XML片段等等。

COMPONENTS

组件

We’ve seen that resources are everywhere on the web, but that doesn’t tell us much about how they’re effectively distributed, managed, and accessed. For this, REST offers
the notion of distributed components, coarse-grained software elements that encapsulate state and behavior and expose them on a distributed network such as the internet.
It’s important to understand that in this book and in the Restlet API, components aren’t typical developer components but architectural actors in a distributed system.

我们已经看到,资源在网络上随处可见我们并不清楚它们是如何有效地分配,管理和访问对此,REST提供分布式组件的概念,分布式组件是粗粒度软件元素,用来封装状态、行为,并在分布式网络(如,互联网)中暴露他们。在这本书或者Restlet API中,理解分布式系统中的组件不是典型的开发组成部分而是架构成员十分重要

Figure C.5 illustrates four components, distributed on the web. The dotted links correspond to a network communication, typically a protocol like HTTP on top of TCP/IP.

图C.5说明四个组件分布在网络上虚线链接对应网络通信,通常是TCP/IP之上的HTTP协议

There are many types of components, such as user agents, origin servers, gateways, and proxies. Well-known user agents are web browsers (like Mozilla Firefox) and common origin servers are web servers and web engines (like Microsoft IIS and Apache Tomcat). Note that the Restlet Framework provides all the technology needed to develop such components.

组件的种类有很多,如用户代理,原始服务器,网关和代理。熟知的用户代理有网页浏览器Mozilla Firefox浏览器常用的原始服务器Web服务器和Web引擎(如微软的IIS和Apache Tomcat Restlet框架提供了所有需要开发这样的组件的技术

CONNECTORS

连接器

Components need to communicate among themselves, and for that they use connectors, as illustrated in figure C.6, to abstract the communication details such as the network
management (like TCP/IP sockets) and the protocol (like HTTP connections).

组件彼此之间使用连接器进行通信图C.6所示,对网络通信细节TCP / IP套接字和协议HTTP连接)进行了抽象说明

In REST, those communications are stateless. The client sends a request that’s self-sufficient, the server returns a response, and the communication is ended. More precisely, in the case of HTTP a socket connection is established that can be made persistent and reused for several transactions.

在REST中,通信无状态的。客户端发送一个请求,该请求包含服务器端所需的所有信息服务器再返回一个响应通信结束更确切地说HTTP情况下将建立套接字连接来进行持续、重复的交互

There are many types of connectors, such as client connectors, server connectors, caches, resolvers, and tunnels. The most common connectors are client connectors (like the Apache HTTP Client library), which send requests, and server connectors (like the Jetty HTTP Server library), which listen for incoming requests and send back responses. The Restlet Framework also provides a comprehensive set of connectors for protocols such as HTTP, POP3, SMTP, FILE, and many more.

有许多类型连接器,如客户连接器,服务器连接,高速缓存,转发器隧道最常见的连接器是客户连接器Apache HTTP客户端)、服务端连接器(Jetty的HTTP服务器客户连接器发送请求服务端连接器侦听传入的请求并发送回响应Restlet框架还提供了一套全面连接器集,支持HTTPPOP3SMTPFILE等多种协议。

 

原创粉丝点击