Untitled
Untitled
Untitled
123
Editors
Erik Wilde Cesare Pautasso
School of Information Faculty of Informatics
UC Berkeley University of Lugano
Berkeley, CA Via Buffi 13
USA 6900 Lugano
[email protected] Switzerland
[email protected]
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 1
Cesare Pautasso and Erik Wilde
Part I Foundations
Part II Design
Index . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 525
Contributors
ix
x Contributors
Web Services
Anybody following the discussions around “Web Services” in recent years is aware
of the fuzzy definition of the term, and a little bit of history can quite easily explain
some of the confusions around current terminology (or use of terminology). The
general idea of using Web technologies to not only deliver Web pages (HTML
documents) between HTTP clients and servers appeared probably more than 10
years ago, when it became clear that the Web and its technical foundations of URIs,
HTTP, and HTML were becoming a very widely deployed information delivery and
service platform. Late in the 1990s, one major approach of implementing this idea
gained a lot of traction, the Simple Object Access Protocol (SOAP) (Box et al. 1999).
SOAP used the new Extensible Markup Language (XML) (Bray et al. 1998) as a
packaging format for a Remote Procedure Call (RPC) mechanism, and thus simply
used the well-established pattern of using RPC mechanisms for implementing
distribution, and packaged it using the Web technologies XML and HTTP. Before
that, most RPC mechanisms used their own packaging/marshalling formats, and
oftentimes even their own delivery protocols, so reusing existing Web technologies
for this made sense, and reduced the amount of proprietary technologies required
for RPC implementations. Additionally, tunneling SOAP messages through HTTP
had the great advantage of using a protocol which would – by default – go
through corporate firewalls and thus greatly facilitate the integration of distributed
applications in business to business scenarios.
While SOAP as a Web implementation of the RPC concept gained a lot of
traction and for a while was synonymous with what people meant when they referred
to “Web Services”, it soon became clear that SOAP, while using Web technologies
for transporting RPC calls, did not really implement a model of “Web Services” that
C. Pautasso ()
Faculty of Informatics, University of Lugano, via Buffi 13, 6900 Lugano, Switzerland
e-mail: [email protected]
took the architectural principles of the Web into account (Vinoski 2008a). While
questions around SOAP’s ability to implement true “Web Services” (instead of just
implementing RPC over the Web) surfaced relatively early (Prescod 2002), SOAP
had already gained considerable momentum and most major vendors had joined the
standardization process of SOAP and related technologies. Representational State
Transfer (REST) (Fielding 2000) as a post-hoc conceptualization of the Web as a
loosely coupled decentralized hypermedia system was coined as a term in 2000,
but it took several years until it became clearly visible in the mainstream that the
model of “Web Services are based on SOAP” had a serious competitor in the form
of services that better conformed to the architectural principles of the Web. Because
those principles were defined by the REST model, this new variety of Web Services
often was referred to as “RESTful Web Services.”
At the time of writing, it is probably safe to say that most people will ask when
somebody refers to “Web Services” to make sure whether they refer to the RPC
model, the REST model, or maybe a more generic and vague concept of any kind
of service delivered using Web technologies. While we cannot change this general
confusion or just fundamental vagueness of this term, it is important to understand
that the most important difference between the two “flavors” of Web services is
the architectural starting point, not so much the actual choice of technologies.
Nowadays, instead of referring to SOAP, oftentimes this flavor of Web services
is referred to as “WS-*” Web services, referring to the multitude of WS-prefixed
middleware interoperability standards that were developed over the years to add
expressivity to the basic SOAP format. Since the main differences are architectural
and not on the level of technology choices, it is important to focus on this level when
comparing these approaches, and several attempts have been made to compare them
as objectively as possible (Pautasso et al. 2008).
It is not possible to simply say that one variety is better than the other, but since
RESTful Web services gained momentum, it has become clear that they do provide
certain advantages in terms of simplicity, loose coupling (Pautasso and Wilde 2009),
interoperability, scalability and serendipitous reuse (Vinoski 2008b) that are not
provided to the same degree by WS-*.
REST Definition
The following constraints can be considered as being the core of the REST
architectural style:
1. Resource Identification: All resources that are relevant for an application (and its
state) should be given unique and stable identifiers. These identifiers should be
global, so that they can be dereferenced independent of context. It is important
that the concept of a “resource” in this case is not limited to the static “things”
that an application is dealing with; it also comprises all information that is
required to talk about those things, such as [transactional documents such as
orders].
2. Uniform Interface: All interactions should be built around a uniform interface,
which supports all the interactions with resources by providing a general and
functionally sufficient set of methods. This constraint is in stark contrast to
RPC, where the main facility for exposing functionality is to define a set of
methods that can be invoked remotely, whereas in REST, there is no such this
as “methods” that can be “called.” Instead, RESTful services expose resources
and resource interactions can only use the uniform interface, or a subset of it.
3. Self-Describing Messages: For the interactions with resources through the uni-
form interface, REST demands to use resource representations that represent the
important aspects of the resources. Those representations have to be designed in
a way that participating parties can get a complete understanding of resources or
relevant state by just inspecting representations. Changes of resource or state also
are communicated by exchanging representations through the uniform interface.
In order to support this constraint, the uniform interface must provide a way in
which information exchanges can “label” representations, so that no out-of-band
information or prior agreement is necessary to “understand” a representations
that is received. It is important to understand that “self-describing” in this case
does not refer to the term as it is sometimes used in the context of semantics, but
only refers to the fact that in order to be able to process a representation that is
exchanged through the uniform interface, no out-of-band information is required.
4. Hypermedia Driving Application State: The representations that are exchanged
are supposed to be linked, so that an application that understands a representation
will be able to find the links, will understand them because their semantics are
defined by the representation, and will be able to use them because they lead
to other identified resources that can be interacted with through the uniform
interface. Without links, it would be impossible to expose new resources or to
provide applications with the possibility to make certain state transitions, and the
hypermedia constraint is probably the one that is most important for supporting
loose coupling (Pautasso and Wilde 2009), because identifiers can be discovered
at runtime and interacted with through the uniform interface, without the need of
any additional previous agreements between interacting parties.
5. Stateless Interactions: This constraint means that each interaction between a
client and a server has to be entirely self-contained; there should be no client
state (often referred to as a “session”) maintained on the server which would
allow an interaction to depend on both the exchanged representation and on the
4 C. Pautasso and E. Wilde
session associated with the client. Any interaction can, of course, cause a change
in a resource, in which case the next interaction with that resource will reflect
that changed resource state. But this change in resource state is different of a
server-maintained client session, because the server only needs to keep track of
resources states, but not of client sessions. This constraint is important to ensure
that the scalability of servers is bound only by the number of concurrent client
requests and not by the total number of clients that they have to interact with.
The general claim of RESTful systems implementing these constraints are that
they are highly scalable and that the interlinking of self-describing representation
formats allows such a system to grow organically and in a decentralized way.
The Web is a very impressive demonstration of a system that does implement
those constraints, and in those places where Web components have violated
those constraints (such as the infamous “session objects” in various Web-oriented
frameworks), important issues such as scalability indeed suffered – and often this
was only discovered when an implementation was almost complete or already
deployed and the server load grew past a critical point.
The main constraints of REST as introduced in the previous section can be regarded
as checkpoints to judge whether a given design is indeed RESTful or not. REST
has become popular enough so that many simply perceive it as a label saying “this
works well on the Web,” and many APIs and services that label themselves as being
RESTful are not.
One popular model for analyzing services has been dubbed the “Richardson
Maturity Model,” named after Leonard Richardson.1 It distinguishes four levels,
named “0” to “3,” and categorizes services according to their adherence to REST
constraints.
• Level 0 are services that simply exchange XML documents over HTTP, such as
XML-RPC. In this case, there is no REST at all, and the only reason why some of
these services my label themselves as REST is because they are not using WS-*
standards. They still (mis)use HTTP as a tunneling protocol.
• Level 1 are services that use resource identification and build interactions on
top of these identified resources. In this case, at least the managed resources are
exposed as identifiable resources so that they can be directly addressed by clients.
However, in most cases resource URIs of Level 1 services correspond to method
1
A similar but more refined classification of HTTP-based APIs was developed by Jan Algermis-
sen in http://nordsc.com/ext/classification of http based apis.html. In
particular, he adds the facet of whether self-describing messages are being used, in the sense that
they have to be explicitly labeled with a media type.
Introduction 5
identifiers and are also used to pass parameters making only limited use of the
HTTP expressive power.
• Level 2 means that in addition to fine-grained resource addressing, also HTTP
methods are properly used as intended by the REST uniform interface. Resource
interactions are thus designed in a way that maps well to this constraint. This not
only means that HTTP’s methods are properly used, it also means that HTTP’s
status codes are used to indicate the correct result of applying a method to
a resource. Since HTTP methods are used properly, HTTP’s classification of
methods as safe and/or idempotent can be used to optimize the system using
intermediaries.
• Level 3 adds hypermedia controls to resource representations, so that clients can
interact with resources by simply following links. Those links in most cases will
need to be typed so that clients can understand the semantics of a link, but the
important issue is that clients can now explore an open space of resources, instead
of having to know everything in advance.
Generally speaking, these attempts at providing a simple framework to
decide “how RESTful” a given service is demonstrates that the current
landscape of services that claim to be RESTful is in need of closer analysis
(Maleshkova et al. 2010). REST as a design principle claims to create designs
that have positive properties, but it is unlikely that these properties can be expected
with designs that ignore certain key constraints.
The current landscape of REST design methods and implementation platforms
is still in development, and it remains to be seen whether research efforts will make
it easier to both design and implement systems that are truly RESTful, and to test
systems for their design qualities in a systematic way.
One of the core components of the early SOAP-oriented approach to Web services
was the idea of a service directory, so that services could be located by using that
directory, and in that directory service descriptions would make it possible to both
understand what a service is about, and how it has to be used. In the world of
SOAP and WS-*, service description is done by using the Web Services Description
Language (WSDL) (Chinnici et al. 2007), and the most popular approach for
managing those descriptions in a directory is to use Universal Description Discovery
and Integration (UDDI) (Clement et al. 2004).
One of the important reasons why service description and discovery is very
important in the WS-* approach is that every service exposes a specific interface,
and without a description of that interface, it is impossible to use that service.
REST’s constraint of a uniform interface, on the one hand, removes the need for a
specific description of a service’s interface, and the constraint of hypermedia driving
application state removes the need for specific discovery of services, because they
are discovered by simply following links.
6 C. Pautasso and E. Wilde
Nevertheless, describing services can be useful, even though it may not be strictly
necessary. One important reason can be to describe a service for documentation,
so that users of that service know what to expect. There is the risk of such a
description and documentation being outdated by newer versions of the service,
so clients of that service should always rely on the actual REST mechanisms (using
the uniform interface, dynamically negotiating the actual representation format, and
following links they find in self-describing messages). However, having an explicit
documentation can be helpful and can be a good way to explain a service in a more
abstract way than just using it, and thus there have been various proposals on how
to describe RESTful services.
One of the most popular approaches is the Web Application Description Lan-
guage (WADL) (Hadley 2006). WADL’s main weakness is the lack of support for the
hypermedia nature of RESTful services; it described resources based on URI path
structures, and thus tightly couples a WADL-based client to a fixed scheme of how
URIs are used. The Resource Linking Language (ReLL) (Alarcón and Wilde 2010)
is another attempt to overcome this limitation of WADL by focusing on resources
and links as the most important aspect of REST service description. Also WSDL
2.0 offers an explicit HTTP binding.
In summary, there is not yet an established machine-processable language for
describing RESTful services, and there is not even consensus whether that would be
useful or required, and if so, what should be described and what should be left open
to avoid tight coupling. Most current RESTful APIs rely on HTML documentation.
In addition to how to describe the basic interaction with RESTful services (their
resources, the representations, the uniform interface, the linking), another question
that has been raised is how to describe services on a semantic level. The main
goal there is to be able to find a service by searching on a semantic level, and
the area of Semantic Web Services has received some attention, in particular in the
areas of the Semantic Web and Linked Data. Many approaches are based on taking
an existing service interface description language, and then augmenting this with
semantic annotations, often in the form of RDF statements that are embedded into
the service description. In such a scenario, it is possible to harvest RDF from a given
set of service descriptions, and then apply standard Semantic Web methods to the
resulting set of RDF data.
Generally speaking, the overlap between REST and Semantic Web activities is
fairly small at the moment, though. This is caused by the fact that on a certain
level of abstraction, the Semantic Web is simply a different set of constraints
than those prescribed by REST. Instead of self-description, the representation
metamodel is fixed and assumed to always be RDF, and REST’s explicitly open-
ended linking (links can point to resources identified by different URI schemes
and thus implementing different uniform interfaces), the Semantic Web prescribes
a more homogenous approach. Harmonizing the worlds of REST and the Semantic
Web, or at least finding good ways to ensure mutually beneficial coexistence, is one
of the current research challenges.
Introduction 7
The original idea for this book came as a result of the First International Workshop
on RESTful Design (WS-REST 2010) that the editors organized at the WWW2010
conference in May 2010 in Raleigh, NC. This workshop was the first attempt to raise
awareness of REST as an important and relevant research topic for academia, but it
was also well-attended by practitioners from the industry. The workshop generated
an interesting set of papers looking at various perspectives of REST as a research
topic (Pautasso et al. 2010), and this book is loosely based on some these workshop
papers, but contains new contributions as well as extensively edited and extended
versions of those papers which did appear in the proceedings.
This book is not intended to be an introduction to REST principles, or to be a
practical guide on how to implement RESTful systems. There are already excellent
books written about that. For example, RESTful Web Services (Richardson and
Ruby 2007) by Leonard Richardson and Sam Ruby may be considered as the most
influential book that started the movement of considering REST as a good choice
for building loosely coupled and scalable services. Allamaraju (2010); Webber et al.
(2010) should also not be missing from the shelf of readers interested in practical
aspects of RESTful services development. The main goal of this book is to bridge
the gap between the sometimes rather abstract work focusing only on research
issues, and the sometimes not very disciplined approaches about how to design and
implement something that qualifies as “being RESTful.”
We would like to express our gratitude to all the authors and the reviewers of the
chapters for their contribution to making this book a reality.
Foundations explores some of the foundations of the REST architectural style, both
in terms of trying to frame the style in a way that allows to understand the main
constraints and their effects on systems design, and in terms of contrasting the
style with the other major style for designing and implementing Web services, the
WS-* approach.
The part about Design has several chapters discussing the important issue of how
to produce a system design that is RESTful, and how to do so in a way that produces
a “good” design. From the point of view of service-orientation, identifying services
as components of a Service-Oriented Architecture (SOA) is the starting point, and
then the challenging question is how to design and implement a system that is a
“good” implementation of such a SOA starting point. An important part of this
part are chapters investigating how several of the core REST constraints influence
the quality of the resulting design, and how important those constraints are for the
eventual system design.
Introduction 9
Development Frameworks address the question how a RESTful system design can
be implemented in a way that is both cost-efficient, but still does allow the system to
evolve in ways which are important. Frameworks can either focus on building back-
end architectures or supporting the development of UIs in the rapidly evolving world
of end-user platforms. In both cases, REST plays an important role in providing
an architecture that should allow to build scalable, decentralized, and shareable
services.
Application Case Studies looks at some scenarios where RESTful approaches have
been used. REST claims to provide certain advantages over the WS-* style of Web
services, but as always, it is important to look at the scenario and the design goals
before any comparisons can be made. In this part, several case studies present such
a comparison, allowing readers to explore how the REST approach has worked in
concrete projects.
REST and Pervasive Computing is one of the areas where RESTful (i.e., Web-
inspired) designs have become popular. One important reason for that is that in many
scenarios of pervasive or ubiquitous computing, loosely coupled architectures and
decentralized designs are essential for being scalable in a world of many sensors
and other Web-enabled devices. The “Internet of Things” has gained quite a bit
of traction as a buzzword, and this part of the book contains chapters describing
forward-looking architectures that make the step forward to implementing a “Web
of Things” that is built on RESTful principles.
While REST is being used as the general style underlying the Web and as a
guiding principle in an increasing number of SOA projects, there still are open
questions and research issues. REST Research addresses a number of those open
issues, such as how to decide on resource granularity, how to model metadata, and
how to handle transactions.
Foundations
1. The Essence of REST Architectural Style (Jaime Navon and Federico Fernandez)
Roy Fielding introduced REST as an architecture style but the experience of the
last few years has shown that there are different interpretations about its essence.
The concepts of Restful application and Resource Oriented Architecture and
their relationships are still source of some debate. In this chapter we start from
Fielding’s proposal to build a more detailed model of the REST architectural
style and then we analyze the model through influence diagrams. The resulting
model can be used to facilitate the understanding of this important architectural
style and the effects and implications of relaxing one or more constraint. Finally
we use the model to analyze and understand the main points of debate around
ROA.
2. REST and Web Services: In Theory and in Practice (Paul Adamczyk, Patrick H.
Smith, Ralph E. Johnson, and Munawar Hafiz)
10 C. Pautasso and E. Wilde
There are two competing architectural styles employed for building Web ser-
vices: RESTful services and services based on the WS-* standards (also known
as “SOAP Web services”). These two styles have separate follower bases, but
many differences between them are ideological rather than factual. In order to
promote the healthy growth of Web services research and practice, it is important
to distinguish arguments for implementation practices over abstract concepts
represented by these styles, carefully evaluating the respective advantages of
RESTful and WS-* Web services. Understanding these distinctions is especially
critical for the development of enterprise systems, because in this domain, tool
vendors have preferred WS-* services to the neglect of RESTful solutions. This
chapter evaluates some of the key questions regarding the real and perceived
distinctions between these two styles of Web services. It analyzes how the current
tools for building RESTful Web services embody the principles of REST. Finally,
it presents select open research questions to further the growth of RESTful Web
services.
Design
can understand in order to use the service correctly. In this chapter, we explain
how to use models to design rich REST services. We use UML class diagrams
and protocol state machines to model the structural and behavioral features
of rich services. The conceptual resource model that represents the structural
feature adds addressability and connectivity features to the designed interface.
The uniform interface feature is offered by constraining the invocation methods
in the state machine to HTTP methods. In addition, to provide the feature of
statelessness in our interface we use a state machine for behavioral modeling.
This oxymoron is addressed by taking advantage of the fact that state invariants
can be defined using query method on resources and the information contained in
their response codes. The rich behavioral specifications present in the behavioral
model show the order of method invocations and the conditions under which
these methods can be invoked along with the expected conditions. We use
this behavioral model to generate contracts in the form of preconditions and
postconditions for methods of an interface.The design approach is implemented
in Django web framework and the contracts generated from the behavioral model
are asserted as contracts in the implemented interface. A proxy interface is also
implemented in Django as a service monitor.
6. Quantifying Integration Architectures (Jan Algermissen)
In a competitive environment, IT systems must be able to quickly respond to
new business requirements. A sufficient level of simplicity and loose coupling
can only be maintained by choosing the right integration styles. This chapter
introduces a metric for quantifying integration architectures that can be used to
guide strategic architectural decisions.
7. FOREST: An Interacting Object Web (Duncan Cragg)
FOREST is a distributed and concurrent object architecture. In FOREST, objects
set their state as a function of their current state plus the state of other objects
observed through links. This observation occurs through either pull or push of
linked object state. Such a programming model is declarative in nature, and
thus very expressive, as well as being naturally concurrent. More importantly, it
maps directly to RESTful distribution over HTTP, using GET for pull and POST
for push of object state, in both directions between interacting servers. Objects
are published into a global interacting object Web which can be described as
“hyperdata.” This mapping of object interaction into RESTful distribution leads
to a symmetric re-interpretation of the hypermedia constraint to “hyperdata as
the engine of hyperdata”.
Development Frameworks
network-based system compliant with the REST architectural style. The system
delivers consistency of the rendered user interfaces with the state of the appli-
cation logic using a stateless networking substrate. We describe the architecture
focusing on how to model the user interfaces as a set of Web resources. Then,
we present the prototype that implements the functionality as an extension of
the Qt framework, which works with different Qt-based user interface toolkits.
Finally, we present a multi-display and multi-user Texas Hold’em application
that shows how the system is used in practice.
9. RESTful Service Development for Resource-Constrained Environments
(Amirhosein Taherkordi, Daniel Romero, Romain Rouvoy, and Frank Eliassen)
The use of resource-constrained devices, such as smartphones and Wireless
Sensor Networks (WSNs) is spreading rapidly in our daily life. Accessing
services from such devices is very common in ubiquitous environments,
but mechanisms to implement and distribute these services remains a major
challenge. Web services have been characterized as a widely-adopted approach
to overcome heterogeneity, while this technology is still heavyweight for
resource-constrained devices. The emergence of REST architectural style as a
lightweight interaction model has encouraged researchers to study the feasibility
of exploiting REST principles to integrate services hosted on devices with
limited capabilities. In this chapter, we discuss the state-of-the-art in applying
REST concepts to develop Web services for WSNs and smartphones, and then
we provide a comprehensive survey of existing solutions in this area. In this
context, we report on the DIGIHOME platform, a home monitoring middleware
solution, which enables efficient service integration in ubiquitous environments
using REST architectural style. In particular, we target our reference platforms
for home monitoring systems, namely WSNs and smartphones, and report our
experiments in applying the concept of Component-Based Software Engineer-
ing (CBSE) in order to provide resource-efficient RESTful distribution of Web
services for those platforms.
10. A REST Framework for Dynamic Client Environments (Erik Albert and Sudar-
shan Chawathe)
We describe methods for building RESTful applications that fully exploit the
diverse and rich feature-sets of modern client environments while retaining
functionality in the absence of these features. For instance, we describe how
an application may use a modern JavaScript library to enhance interactivity
and end-user experience while also maintaining usability when the library is
unavailable to the client (perhaps due to incompatible software). These methods
form a framework that we have developed as part of our work on a Web
application for presenting large volumes of scientific datasets to non-specialists.
The REST Framework for Dynamic Client Environments (RFDE) is a method
for building RESTful Web applications that fully exploit the diverse and rich
feature-sets of modern client environments while retaining functionality in the
absence of these features. For instance, we describe how an application may use
a modern JavaScript library to enhance interactivity and end-user experience
while also maintaining usability when the library is unavailable to the client
Introduction 13
13. Managing Legacy Telco Data Using RESTful Web Services (Damaris Fuentes-
Lorenzo, Luis Sánchez, Antonio Cuadra-Sanchez, and Mar Cutanda Rodrı́guez)
Our chapter aims to explain the activities to transform an existing collection of
data into resources ready to be easily searched and queried, applying advanced
web technologies such as RESTful web techniques. These technologies have
been deployed in this work over traditional tools dealing with services offered
to customers in a real Telecom company.
14. Case Study on the Use of REST Architectural Principles for Scientific Analysis:
CAMERA – Community Cyberinfrastructure for Advanced Microbial Ecology
Research and Analysis (Abel Lin, Ilkay Altintas, Chris Churas, Madhusudan
Gujral, Jeff Grethe, and Mark Ellisman)
The advent of Grid (and by extension Cloud) Computing along with Service
Orientated Architecture (SOA) principles have led to a fundamental shift in the
development of end-user application environments. No longer do stand-alone
14 C. Pautasso and E. Wilde
several services on the Web (e.g., Twitter, Wikipedia, etc.) with RFID data to
allow managers along the supply chain and customers to get comprehensive
data about their products.
17. Leveraging the Web for a Distributed Location-Aware Infrastructure for the
Real World (Vlad Trifa, Dominique Guinard, and Simon Mayer)
Since GPS receivers have become a commodity anyone could access and use
location information simply and freely. Such an easy access to ones’ location is
instrumental to development of location-aware applications. However, existing
applications are static in that they do not model relations between places
and mobile things. Moreover, these applications do not allow to easily map
the physical location of mobile devices to virtual resources on the Internet.
We attempt to bridge this gap by extending the base concepts that make up
the Internet with the physical location of devices, in order to facilitate the
development of Web-based location-aware applications for embedded mobile
devices. In this chapter, we propose a simple infrastructure for the “Web of
Things” that extends the existing Web to enable location-aware applications.
The proposed solution enables a natural hierarchical way to search for location-
aware devices and the services they provide.
18. RESTful Service Architectures for Pervasive Networking Environments (Mauro
Caporuscio, Marco Funaro, and Carlo Ghezzi)
Computing facilities are an essential part of the fabric of our society, and an
ever-increasing number of computing devices is deployed within the environ-
ment in which we live. The vision of pervasive computing is becoming real.
To exploit the opportunities offered by pervasiveness, we need to revisit the
classic software development methods to meet new requirements: (1) pervasive
applications should be able to dynamically configure themselves, also benefit-
ing from third-party functionalities discovered at run time and (2) pervasive
applications should be aware of, and resilient to, environmental changes. In this
chapter, we focus on the software architecture, with the goal of facilitating both
the development and the run-time adaptation of pervasive applications. More
specifically we investigate the adoption of the REST architectural style to deal
with pervasive environment issues. Indeed, we believe that, although REST has
been introduced by observing and analyzing the structure of the Internet, its
field of applicability is not restricted to it. The chapter also illustrates a proof-
of-concept example, and then discusses the advantages of choosing REST over
other styles in pervasive environments.
REST Research
representations. Based on the insights gained from the API review, we motivate
the concept of an entity as well as its boundaries. Eventually, we discuss the
relevance of the entity concept for publishers and consumers of Web data, as
well as the impact on Web data design issues.
20. A Resource Oriented Multimedia Description Framework (Hildeberto Men-
donca, Vincent Nicolas, Olga Vybornova, and Benoit Macq)
This chapter presents a multimedia archiving framework to describe the content
of multimedia resources. This kind of content is very rich in terms of meanings
and archiving systems have to be improved to consider such richness. This
framework simplifies the multimedia management in existing applications,
making it accessible for non-specialized developers. This framework is fully
implemented on the REST architectural style, precisely mapping the notion
of resource with media artifacts, and scaling to address the growing demand
for media. It offers an extensive support for segmentation and annotation to
attach semantics to content, helping search mechanisms to precisely index those
content. A detailed example of the framework adoption by a medical imaging
application for breast cancer diagnosis is presented.
21. Metadata Architecture in RESTful Design (Antonio Garrote and Marı́a N.
Moreno Garcı́a)
This chapter is an overview of the role that metadata plays in the design of
RESTful services and APIs. The chapter describes how metadata can be asso-
ciated to resources using the HTTP protocol and other standard technologies
like RDFa. Techniques for metadata extraction and metadata discovery are also
introduced. The ultimate goal of the chapter is to provide tools to build truly
self-describing RESTful resources.
22. RESTful Services with Lightweight Machine-Readable Descriptions and Se-
mantic Annotations (Jacek Kopecky, Tomas Vitvar, Carlos Pedrinaci, and Maria
Maleshkova)
REST was originally developed as the architectural foundation for the human-
oriented Web, but it has turned out to be a useful architectural style for
machine-to-machine distributed systems as well. The most prominent wave of
machine-oriented RESTful systems are Web APIs (also known as RESTful
services), provided by Web sites such as Facebook, Flickr, and Amazon to
facilitate access to the services from programmatic clients, including other
Web sites. Currently, Web APIs do not commonly provide machine-processable
service descriptions which would help tool support and even some degree
of automation on the client side. This chapter presents current research on
lightweight service description for Web APIs, building on the HTML docu-
mentation that accompanies the APIs. HTML documentation can be annotated
with a microformat that captures a minimal machine-oriented service model, or
with RDFa using the RDF representation of the same service model. Machine-
oriented descriptions (now embedded in the HTML documentation of Web
APIs) can also capture the semantics of Web APIs and thus support further
automation for clients. The chapter includes a discussion of various types and
Introduction 17
degrees of tool support and automation possible using the lightweight service
descriptions.
23. Towards Distributed Atomic Transactions Over RESTful Services (Guy Pardon
and Cesare Pautasso)
There is considerable debate in the REST community whether or not transaction
support is needed and possible. This chapter’s contribution to this debate is
threefold: we define a business case for transactions in REST based on the
Try-Cancel/Confirm (TCC) pattern; we outline a very light-weight protocol that
guarantees atomicity and recovery over distributed REST resources; and we
discuss the inherent theoretical limitations of our approach. Our TCC for REST
approach minimizes the assumptions made on the individual services that can be
part of a transaction and does not require any extension to the HTTP protocol.
A very simple but realistic example helps to illustrate the applicability of the
approach.
References
Rosa Alarcón and Erik Wilde. RESTler: Crawling RESTful Services. In Michael Rappa, Paul
Jones, Juliana Freire, and Soumen Chakrabarti, editors, 19th International World Wide Web
Conference, pages 1051–1052, Raleigh, North Carolina, April 2010. ACM Press, New York.
Subbu Allamaraju. RESTful Web Services Cookbook. O’Reilly & Associates, Sebastopol, Califor-
nia, February 2010.
Don Box, Gopal Kavivaya, Andrew Layman, Satish Thatte, and Dave Winer. SOAP: Simple Object
Access Protocol. Internet Draft draft-box-http-soap-01, November 1999.
Tim Bray, Jean Paoli, and C. Michael Sperberg-McQueen. Extensible Markup Language (XML)
1.0. World Wide Web Consortium, Recommendation REC-xml-19980210, February 1998.
Roberto Chinnici, Jean-Jacques Moreau, Arthur Ryman, and Sanjiva Weerawarana. Web Services
Description Language (WSDL) Version 2.0 Part 1: Core Language. World Wide Web Consor-
tium, Recommendation REC-wsdl20-20070626, June 2007.
Luc Clement, Andrew Hately, Claus von Riegen, and Tony Rogers. UDDI Version 3.0.2.
Organization for the Advancement of Structured Information Standards, UDDI Spec Technical
Committee Draft, October 2004.
Florian Daniel, Maristella Matera, Jin Yu, Boualem Benatallah, Regis Saint-Paul, and Fabio Casati.
Understanding UI Integration: A Survey of Problems, Technologies, and Opportunities. IEEE
Internet Computing, 11(3): 59–66, May–June 2007.
Roy Thomas Fielding. Architectural Styles and the Design of Network-based Software Architec-
tures. PhD thesis, University of California, Irvine, Irvine, California, 2000.
Marc Hadley. Web Application Description Language (WADL). Technical Report TR-2006-153,
Sun Microsystems, April 2006.
Maria Maleshkova, Carlos Pedrinaci, and John Domingue. Investigating Web APIs on the
World Wide Web. In Proceedings of the 8th IEEE European Conference on Web Services
(ECOWS2010), pages 107–114, December 2010.
Cesare Pautasso. Composing RESTful Services with JOpera. In Alexandre Bergel and Johan Fabry,
editors, International Conference on Software Composition 2009, volume 5634 of Lecture
Notes in Computer Science, pages 142–159, Zürich, Switzerland, July 2009. Springer-Verlag,
Berlin, Heidelberg, New York.
18 C. Pautasso and E. Wilde
Cesare Pautasso. On Composing RESTful Services. In Frank Leymann, Tony Shan, Willen-Jan
van den Heuvel, and Olaf Zimmermann, editors, Software Service Engineering, number 09021
in Dagstuhl Seminar Proceedings, Dagstuhl, Germany, June 2009.
Cesare Pautasso. RESTful Web Service Composition with BPEL for REST. Data & Knowledge
Engineering, 68(9): 851–866, September 2009.
Cesare Pautasso and Erik Wilde. Why is the Web Loosely Coupled? A Multi-Faceted Metric for
Service Design. In Juan Quemada, Gonzalo León, Yoëlle S. Maarek, and Wolfgang Nejdl,
editors, 18th International World Wide Web Conference, pages 911–920, Madrid, Spain, April
2009. ACM Press, New York.
Cesare Pautasso, Erik Wilde, and Alexandros Marinos, editors. First International Workshop on
RESTful Design (WS-REST 2010), Raleigh, North Carolina, April 2010.
Cesare Pautasso, Olaf Zimmermann, and Frank Leymann. RESTful Web Services vs. “Big” Web
Services: Making the Right Architectural Decision. In Jinpeng Huai, Robin Chen, Hsiao-
Wuen Hon, Yunhao Liu, Wei-Ying Ma, Andrew Tomkins, and Xiaodong Zhang, editors, 17th
International World Wide Web Conference, pages 805–814, Beijing, China, April 2008. ACM
Press, New York.
Paul Prescod. Roots of the REST/SOAP Debate. In 2002 Extreme Markup Languages Conference,
Montréal, Canada, August 2002.
Leonard Richardson and Sam Ruby. RESTful Web Services. O’Reilly & Associates, Sebastopol,
California, May 2007.
Steve Vinoski. RPC and REST: Dilemma, Disruption, and Displacement. IEEE Internet Comput-
ing, 12(5): 92–95, September 2008.
Steve Vinoski. Serendipitous Reuse. IEEE Internet Computing, 12(1): 84–87, January 2008.
Jim Webber, Savas Parastatidis, and Ian Robinson. REST in Practice: Hypermedia and Systems
Architecture. O’Reilly & Associates, Sebastopol, California, September 2010.
Part I
Foundations
Chapter 1
The Essence of REST Architectural Style
Introduction
REST is usually referred to, as it was originally introduced in the Chap. 5 of the
Ph.D. dissertation of Dr. Roy Fielding: an architectural style (Fielding 2000). To
fully understand the idea it is necessary to read the full dissertation since REST
J. Navon ()
Department of Computer Science, Universidad Catolica de Chile, Santiago, Chile
e-mail: [email protected]
rationale cannot be understood without the definitions and concepts of Chaps. 1–3
and the description of the WWW architecture requirements of Chap. 4. The problem
is, that even after reading the complete dissertation you might still have questions
related more to the real-world implications than to abstract theoretical software
engineering issues.
Why is that, in spite of the huge success of REST, there is still so much
debate about whether a given service API should be considered REST? What is
the difference between REST and Restful? What is the relationship between REST
and resource oriented architecture (ROA)?
First there is this slippery thing called Architectural Style. Fielding defines it
as a “coordinated set of architectural constraints that restricts the roles/features of
architectural elements and the allowed relationships among those elements within
any architecture that conform to that style”. This is why, consistent with this
definition, he introduces REST precisely trough a set of constraints, namely client–
server, stateless, cache, uniform interface, etc.
Explaining REST by introducing constraints associated to a number of primitive
architectural styles is just fine for a doctoral dissertation but it leaves a lot of room to
interpretation. This is the source of some heated debates about concrete architectures
that might be “betraying” the REST principles.
Richardson and Ruby (2007) in their book present what they call a “ROA” as a
simple set of guidelines that guarantees a RESTful architecture. They make clear
though that there are other concrete architectures that may also be RESTful.
Not only is the concept of architectural style is problematic, there is no
complete agreement on what is really software architecture. As defined by the
Institute of Electrical and Electronics Engineers (IEEE) Recommended Practice
for Architecture Description of Software-Intensive Systems (IEEE standard 1471–
2000), architecture is “the fundamental organization of a system embodied in its
components, their relationships to each other, and to the environment, and the
principles guiding its design and evolution”. This definition is fairly abstract and
applies to systems other than just software. Meanwhile, Fielding emphasizes that
software architecture is an abstraction of the run-time behavior of a software system
and not just a property of the static software source code.
Bass et al. (2003) define software architecture as “structures of the system, which
comprise software elements, the externally visible properties of those elements, and
the relationships among them”. The plural in structures acknowledges the possibility
of more than one structure, each of them conveying architectural information. Some
may be more related to the static structure and some more to the dynamic aspects.
We believe that Roy Fielding’s dissertation is indeed the key document to dive
deeper into the essence of REST; a document that, as Martin Fowler puts forward
in his foreword in a recent book (Webber et al. 2010), “is far more often referred to
than it is read”. We hope that this chapter will contribute to a better understanding
of REST and also as a framework to evaluate and discuss new proposals of software
architectures and architecture styles.
1 The Essence of REST Architectural Style 23
The REST entry in the table reflects the fact that this architectural style can be
derived from several styles (see Fig. 1.1).
Although not necessary, it is nice to use a software tool to build the diagrams. We
used Flying Logic1 flexible visual modeling tool. This is a commercial product but
there is a free reader available so people who only want to read de diagrams do not
need to buy the full product.
The influence diagram nodes corresponding to utility, decisions and chances were
represented by tagged boxes (Fig. 1.2). The little circles present in some arrows and
boxes denote commentaries (we used them to copy fragments from the dissertation).
A black arrow, between a decision and a chance, means that the decision has a
positive causal relationship with the chance whereas a grey arrow means that the
decision has a negative causal relationship with the chance.
1
http://www.flyinglogic.com
1 The Essence of REST Architectural Style 27
An arrow between a chance and a utility can only be black and denotes a positive
causal relationship between the chance and the utility node. An arrow between two
utilities means that the first utility is a child of the second one. Arrows between
decisions were used to denote temporal precedence.
Because of limitations in the tool, we do not use arrows to connect decisions.
Instead, we describe the sequence of decisions that defines REST as a hierarchy of
decision sets. This improves visibility at the cost of reduced understandability. If a
decision is outside a given set, it means that it was made after the decisions inside
the set, but if two or more decisions are in the same set, the user could not know
which was done before the other, so he would have to get this information from
another source (e.g. comments).
Figure 1.3 shows part of the REST influence diagram. Each decision represents
an architectural style used in the derivation of REST, and each chance explains
why a given decision affects a given utility. The dashed rectangles in the diagram
can collapse its contents while maintaining the arrows going from the group to the
outside (Fig. 1.4 shows the result of collapsing both named rectangles).
A more complete influence diagram for REST in the condensed mode is
presented in Fig. 1.5. If we delete all the chances and decisions from the diagram
and expand all the utility nodes, we get a horizontal version of the tree (Fig. 1.6).
To produce the chances we performed an exhaustive revision of the dissertation.
Once we identified why a decision was related to a utility node, either we created
a new chance between both nodes or we reused an already existent one. In order
to maximize the reuse of chances, we tried to generalize each chance as much as
possible.
28 J. Navon and F. Fernandez
Relating general network based software qualities with the goals of the WWW
architecture is not straightforward. Furthermore, to make the diagram easier to
read and understand, we eliminated some redundant utility nodes (portability),
transformed others into chances (visibility), divided some utilities into lower
1 The Essence of REST Architectural Style 29
level utility nodes (simplicity) and rearranged the hierarchy of utility nodes (UP
Performance, Net Performance and Net Efficiency).
Initially, every decision node corresponded to one of the styles used in the
derivation of REST, but then we decided to include decisions of lower granularity
by dividing some styles into smaller parts.
Figure 1.7 shows the decisions that compose the Uniform Interface in the
REST influence diagram. The decisions we included are Standard Representations,
Standard Operations, and Hypermedia as the User Interface.
While developing the diagram, we also extracted some decisions and correspond-
ing chances that were not explicitly explained as parts of REST derivation. Those
decisions are shown in Fig. 1.8. Some of them can be considered constraints that
can be added to REST to characterize a more restricted architectural style.
30 J. Navon and F. Fernandez
The ROA as defined in Richardson and Ruby (2007) is “a way of turning a problem
into a RESTful web service: an arrangement of URIs, HTTP, and XML that works
like the rest of the Web, and that programmers will enjoy using.” Another term
used for the same purpose is Web Oriented Architecture, which is used by some
IT consultants to name the application of the WWW standard protocols and proven
solutions for the construction of distributed software systems (Hinchcliffe 2008).
Recently, it became clear that some of these approaches were not following all
of the REST constraints, so practitioners started to debate, not only about ways to
follow those constraints, but also about how important was to follow all of them.
To further test the applicability of our REST model, we will try now to provide
an answer to a recent question that has been subject of a strong: Considering the
1 The Essence of REST Architectural Style 31
2
http://roy.gbiv.com/untangled/2008/on-software-architecture
3
http://roy.gbiv.com/untangled/2009/it-is-okay-to-use-post
4
http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
32 J. Navon and F. Fernandez
ROA lacks only one decision: “Hypermedia as the engine of application state”.
There is also an optional decision: “Hypermedia as the user interface” (resource
representations should be connected by links).
If we focus only in the arrows going from these two decisions we get the diagram
of Fig. 1.10. Clearly, the constraint “Hypermedia as the user interface” was added
to REST as a means to lower the WWW entry barriers for human readers and
authors. This explains why it didn’t make much sense for developers thinking rather
in machine interaction.
On the other hand, “Hypermedia as the engine of application state” affects two
chances that would be kept in the diagram even if we think that the user is a machine,
and these chances impact Scalability and Evolvability.
So, why did the ROA proponents are ready to relax this constraint? Because
in the context of machine-to-machine integration, it may require representations
containing semantic hypermedia and this in turn would negatively affect the utilities
“Simplicity for Application Developers” and “Performance”. The additional effort
is not considered worthwhile when compared to the benefits of Scalability and
Modifiability.
The answer to the original question, thus, is that by not following the hypermedia
constraint, the architectures conforming to ROA are indeed less scalable and
modifiable than architectures conforming to REST.
1 The Essence of REST Architectural Style 33
We do not know exactly how less scalable and modifiable would be. The tradeoff
of adding these constraints to ROA at the cost of lower simplicity and performance
must be the subject of further research. In fact, one interesting research line could
explore a way to modify the influence diagram technique to provide not only
qualitative but also quantitative assessments, to help the architect to reason more
effectively about the impact of different architectural styles on the desired set of
software qualities.
The result obtained through REST influence diagram may not be surprising to
REST practitioners, but now we can guarantee that it is founded in the knowledge
included in the dissertation and nothing else. This is one of the most valuable
properties of this model. A second valuable property is that adding decisions and
chances can easily extend the model. For example, one could change both decisions
in Fig. 1.10 by one group called “Semantic hypermedia as the engine of application
state”, and add to that group decisions like “Machine-readable hypermedia as the
client interface” and “Shared semantic data model between Client and Server,” thus
starting to build a new architectural style that reuses part of REST structure and
design rationale.
References
Bass, L., Clements, P., and Kazman, R. (2003) Software Architecture in Practice, 2nd Ed., Addison
Wesley Professional, Reading, MA, USA.
Chung, L., Nixon, B. A., Yu, E., and Mylopoulos, J. (1999) Non-Functional Requirements in
Software Engineering. International Series in Software Engineering, Vol. 5, Springer, Berlin,
Heidelberg, New York.
Fielding, R. T. (2000) Architectural styles and the design of network-based software architectures.
Ph.D. Dissertation, University of California, Irvine.
Hinchcliffe, D. (2008) What is WOA? It’s the Future of Service-Oriented Architecture (SOA). Dion
Hinchcliffe’s Blog – Musings and Ruminations on Building Great Systems. Retrieved January
11th, 2008, http://hinchcliffe.org/archive/2008/02/27/16617.aspx.
Jansen, A. and Bosch, J. (2005) Software Architecture as a Set of Architectural Design Decisions.
Proceedings of the 5th Working IEEE/IFIP Conference on Software Architecture, WICSA ’05,
Pittsburgh, PA, USA.
Johnson, P., Lagerström, R., Närman, P., and Simonsson, M. (2007) Enterprise architecture
analysis with extended influence diagrams. Information Systems Frontiers, 9 (2–3). doi:
10.1007/s10796–007–9030-y.
Richardson, L. and Ruby, S. (2007) Restful web services. O’Reilly Media Inc. USA.
Webber, J., Parastaditis, S., and Robinson, I. (2010) Rest in Practice, O”Reilly Media Inc., USA.
Chapter 2
REST and Web Services: In Theory
and in Practice
Abstract There are two competing architectural styles employed for building Web
services: RESTful services and services based on the WS– standards (also known
as “SOAP Web services”). These two styles have separate follower bases, but many
differences between them are ideological rather than factual. In order to promote the
healthy growth of Web services research and practice, it is important to distinguish
arguments for implementation practices over abstract concepts represented by these
styles, carefully evaluating the respective advantages of RESTful and WS– Web
services. Understanding these distinctions is especially critical for the development
of enterprise systems, because in this domain, tool vendors have preferred WS–
services to the neglect of RESTful solutions. This chapter evaluates some of the key
questions regarding the real and perceived distinctions between these two styles of
Web services. It analyzes how the current tools for building RESTful Web services
embody the principles of REST. Finally, it presents select open research questions
to further the growth of RESTful Web services.
Introduction
Since its inception, the Web has been an open frontier of exploration in software
and network system design. New ideas were tried and tested first, but organized
and standardized later, once they proved their utility. For example, HTTP, the
transport protocol of the Web, had been in use for more than half a decade before
its state of practice was written down as HTTP/1.0 (Berners-Lee et al. 1996)
in May 1996. But the standardization process continued until 1999, when the
final revision of HTTP/1.1 (Fielding et al. 1999) standard was completed. The
architectural principles behind HTTP and other Web standards were described by
P. Adamczyk ()
Booz Allen Hamilton Inc.
e-mail: [email protected]
Fielding (2000), thus completing the process. HTML has followed a similar path.
It started out with a simple set of tags for structuring text and graphics on Web pages.
As the number of content types [new multimedia formats, more sophisticated ways
of displaying text, interactive Web pages (Garrett 2005)] grew, the HTML tags were
pressed into service of displaying them in various non-standard ways. After nearly
two decades of this growth, new multimedia HTML tags are finally going to be
added and standardized by W3C in HTML5, which is expected to be completed in
2012 (Hickson 2010).
A similar sequence of events – simple beginnings leading to an unruly explosion
followed by some type of organization – can be observed in the realm of Web
services. The first Web services were built for passing remote procedure calls
(RPCs) over the Web. The idea took off quickly and resulted in a large collection
of standards (beginning with SOAP and WSDL). Surprisingly, these standards were
defined with little consideration for the contemporary practice; sometimes before
there were any implementations to standardize. The end result of this premature
standardization was confusion, rather than order that standards usually bring. In
response, an alternative style of Web services, built according to the rules of the
Web, began to appear. These (so-called RESTful) Web services are maturing, or,
more precisely: people are re-learning to use the tried-and-true standards of the Web
and applying them when building Web services. As the two styles of Web services
are used side-by-side, one hopes that they will begin to have positive effects on one
another. Currently, the interactions and comparisons begin to reach a constructive
stage, so this is a good time to stop and reflect on the current state of affairs.
In particular, this chapter focuses on the interpretation of the widely used term,
REST. Roy Fielding coined the term and codified it under four principles. In
practice, people are implementing it in many ways, each harboring certain implicit
conventions of the developers. Following the path of practice dictating the standards,
we raise questions about the previously accepted views about REST and Web
services, and identify the challenges raised by the current state of practice.
Having a standard meaning of RESTfulness would engage the enterprise commu-
nity. REST has been an important part of “renegade” Web services, appealing more
to independent, small-scale and “hip” developers. With concerted research effort,
it would fulfill the stricter requirements of enterprise Web services; conversely, the
enterprise services would benefit from its simplicity.
We begin by summarizing the theory behind RESTful Web services, and draw
a comparison with WS– services. Next, we look into the usage patterns of Web
services in practice: both RESTful services and WS– services. Then, we discuss
some of the problems facing the existing RESTful services, how these problems
make it harder to apply RESTful services to large enterprise systems, and how tools
for implementing them help to alleviate these problems. We conclude by surveying
some of the outstanding research problems of RESTful Web services.
Conventions used in this chapter. We consider two dominant styles of Web ser-
vices: RESTful and WS–. The term Representational State Transfer (REST) was
coined by Roy Fielding to identify an architectural style based on a set of principles
2 REST and Web Services: In Theory and in Practice 37
Although this task was undertaken many times before, presenting a fair comparison
of WS– and RESTful Web services remains a daunting task. In this section, we
will describe their guiding principles and summarize two studies that compare these
architectural styles.
Principles
Roy Fielding documented REST based on the principles that emerged as the Web
evolved (Fielding 2000). He noticed that Web servers, clients, and intermediaries
shared some principles that gave them extensibility to work on the large-scale
of the Internet. He identified four principles of REST (which he called con-
straints) (Fielding 2000):
1. Identification of resources.
2. Manipulation of resources through representations.
3. Self-descriptive messages.
4. Hypermedia as the engine of application state (abbreviated HATEOAS).
These principles describe the architecture of systems and interactions that make
up the Web. The building blocks of the Web are called resources. A resource
is anything that can be named as a target of hypertext (e.g., a file, a script, a
collection of resources). In response to a request for a resource, the client receives a
representation of that resource, which may have a different format than the resource
owned by the server. Resources are manipulated via messages that have standard
meanings; on the Web, these messages are the HTTP methods. The fourth principle
means that the state of any client–server interaction is kept in the hypermedia they
exchange, i.e., links, or URIs. Any state information is passed between the client and
the server in each message, thus keeping them both stateless. It’s easy to check any
design against such a simple description. Any discrepancies will be easy to identify.
However, this simplicity is deceptive – if one tries to simplify it even more, the
entire design suffers. We will discuss concrete examples of oversimplifying REST
in some Web services in “REST Concepts in Practice”.
38 P. Adamczyk et al.
The actual comparison has two problems. First, they use the numbers of
architectural decisions and available alternatives to choose which style is better.
But counting is hardly the right metric – not every decision point has the same
weight. Second, most decision points on every level have two options, one for each
style, indicating that they actually have nothing in common. Only in a few cases do
both styles require a decision on the same question. Nevertheless, this paper is the
best-conducted comparison of principles available today. It’s unbiased, thoroughly
researched, and it examines multiple points of view.
Richardson and Ruby book. A second comparison of note is presented in
the book, “RESTful Web Services” (Richardson and Ruby 2007). The authors,
Richardson and Ruby, discuss the principles that are relevant to all systems available
on the Web. Even though their book is biased toward RESTful Web services, the
principles they discuss would be a better starting point for making a fair comparison
between the two styles.
They identify four system properties of RESTful services: (1) uniform interface,
(2) addressability, (3) statelessness, and (4) connectedness. In RESTful Web
services, these properties are embodied in resources, URIs, representations, and the
links between them. Lets consider how these principles apply to WS– services.
Addressability and some form of connectedness are embedded in the WSDL
definition of bindings and ports. Many WS-*services are stateless (although it is
not an explicit requirement). Having a uniform interface shared by all services is
the only property not supported by WS–. Thus, WS– services exhibits three of
these four properties. WS– services achieve these properties via different means,
but these properties are clearly relevant to both, and therefore a good choice for
comparison.
Richardson and Ruby use a similar approach to evaluate how RESTful Web
services offer capabilities which are important for enterprise-level integration. They
show how to implement transactions, reliability, message-level security (concepts
that Pautasso et al mention, but do not discuss) using REST. We will return to these
three concepts in “Ready for the Enterprise?”.
Both styles of Web services possess certain characteristics that guide their design
and development, although they are defined in ways that make it difficult to compare
them side-by-side. Next, we will look at how services are used in practice, which
provides yet another perspective for comparing them.
One obstacle to studying existing Web services is the fact that many of them
are not accessible to the outside world, because they are proprietary. Proprietary
systems have different requirements (fewer security threats due to well known
vulnerabilities, no need to adhere to common standards) that result in different
choices of Web services technologies. Industry studies provide some insight about
40 P. Adamczyk et al.
the trends in proprietary Web services, such as the planned and actual usage of
Web services. One industry survey shows that the adoption of SOAP standard by
enterprises increased 31% between 2002 and 2003 (Correia and Cantara 2003).
A follow-up survey from 2006 notes that about 12% of enterprises report completing
a “full enterprise roll-out” and another 21% are in process, while 60% are still
studying the feasibility of such projects (McKendrick 2011). Both surveys report
only on WS– Web services.
More recent results show a new trend. According to a 2008 Gartner
Survey (Sholler 2008) there has been an increase in the number of organizations
implementing Web services using Representational State Transfer (REST) and
Plain Old XML (POX). RESTful Web services are considered less complex, require
fewer skills, and have a lower entry cost than WS– Web services. However, the
surveyors believe that RESTful services by themselves do not provide a complete
enterprise solution.
Turning our attention to public Web services, two earliest surveys of public Web
services (Kim and Rosu 2004; Fan and Kambhampati 2005), from 2004, discussed
strictly WS– services. Both surveys showed that some of WS– standards (most
notably SOAP and WSDL) were successfully used in practice, but they did not
cover other standards. These surveys have been limited to WS– services, perhaps
unintentionally, because they considered the presence of a WSDL file as a necessary
prerequisite of a valid Web service.
In order to build on their work, we have studied various Web services repositories
(including the only extant ones cited by these surveys) to analyze the available
public Web services from the perspective of architectural styles they follow. We
performed these surveys in mid-2007 and again in mid-2010 by examining the Web
services listed in the following repositories:
• xmethods.net
• webservicex.net
• webservicelist.com
• programmableweb.com
These repositories describe only publicly accessible Web services. While SOAP
services are easy to find automatically (by checking for the presence of the WSDL
file), RESTful services are documented in non-standard ways that make their
automatic discovery impossible. We examined the type of each service manually,
by reading its documentation. We have identified four mutually exclusive categories
of Web service styles: RESTful, WS–, XML-RPC, and Other. XML-RPC was the
first attempt at encoding RPC calls in XML (which later evolved into SOAP). The
Other category groups many other types of services, including RSS feeds, Atom,
XMPP, GData, mail transfer protocols. The most popular styles of Web services in
each repository are shown in Table 2.1.
At a first glance, these results could not possibly paint a more inconsistent
picture. Each repository shows a different trend. However, the differences arise from
the nature/focus of these repositories. The first two repositories, which list (almost)
exclusively WS– services, advertise services that require payment for access. The
2 REST and Web Services: In Theory and in Practice 41
second repository appears to be closed to registration (we could not find any way
to contact the owners to register a new service) which may imply that they are
advertising only the services which they own. The numbers of services listed in
these two repositories have not changed much in the last 3 years.
The latter two repositories feature a variety of Web service styles, with RESTful
and WS– services being the two most popular styles in both the 2007 and 2010
tally. Programmableweb.com is the only repository that shows an increase in the
number of services; a fivefold increase over the observed period. Its data shows
increase in all types of services, but mostly in RESTful ones, which currently
account for about 75% of services listed, compared to less than 50% 3 years earlier.
These results, although insufficient to determine conclusively which style is more
popular (and why), indicate that a wide variety of public Web services is available
and that a sizable number of RESTful services has been created recently, even if not
all of them are widely known.
With so many public Web services available to study, we were able to identify many
trends in how closely services follow the theoretical principles of REST. WS–
principles are encoded in XML-based standards that are easy to enforce by tools.
The designer selects the necessary features (standards), then finds the tool that
supports them. The actual development is easy. But since this book is about REST,
we will focus on RESTful Web services, and refer to WS– only to compare and
contrast specific features. In this section, we will review how REST principles are
embodied and implemented in actual RESTful Web services.
According to the principles of REST, which we introduced in “Web Services in
Theory”, every resource is identified with a URI. In response to HTTP messages,
resources return their representations to clients, or the clients modify the resources.
42 P. Adamczyk et al.
Fig. 2.1 Examples of RESTful hypermedia defined as URIs. Examples 1–5 use query strings of
form key=value. Examples 4a–c show alternative ways to define the same resource. Example 6
uses the structural form instead of query strings: the order of keywords is defined by the server’s
API so that the client need not list keys, only values, in the URI
Proponents of RESTful Web services typically say that every service needs to follow
the CRUD model (Kilov 1990). This concept, borrowed from the database domain,
defines one method for creating, reading, updating, and deleting a resource on the
server (corresponding to POST, GET, PUT, and DELETE methods). This approach
enables invoking different operations on a resource by applying a different HTTP
method. This is only possible if resources are defined in a correct way. Figure 2.1
shows some examples of valid URIs. All of these URIs can be accessed with the
GET method.
One good example of a Web service that follows the principles of REST is Ama-
zon S3 (Simple Storage Service) (Amazon 2011). S3 defines many resources and
uses HTTP methods (POST, GET, PUT, DELETE, even HEAD) for manipulating
them. It uses HTTP error codes correctly and shows how to map various errors
to HTTP codes (the API references 13 unique HTTP status codes in the 300–500
range). S3 also supports caching by including ETag header that clients can use in
conditional GET.
However, most RESTful services are not designed as diligently. They neglect
to follow the principles in various ways. In order to evaluate the current level of
understanding of REST, we will look at some representative mistakes from the
perspective of the 4 principles of REST.
2 REST and Web Services: In Theory and in Practice 43
Identification of Resources
Every designer of a RESTful service must answer the question: What constitutes
the resources of the system? Ideally, any concept within the system that has a
representation should be exposed as a resource.
In WS– services, clients invoke API methods on the server by passing SOAP
messages to a well-known service end-point defined with a URI. These service
end-points are the only resources used by WS–. Some RESTful service follow
the same pattern – they define one path component to be used in every URI and
encode parameters for the corresponding server method in the query strings. This is
wrong, because in REST resources are supposed to be accessed with self-descriptive
messages (e.g. HTTP methods) that have well-defined semantics. Looking at
Example 5 in Fig. 2.1, it’s OK to access this resource via GET, but what would be
the intended semantics for PUT and other HTTP methods? Such a resource can only
accept read-only requests, the way Google’s search service works. But if the clients
need to be able to modify the resources, this style of resources is not appropriate.
Defining resources is hard. Consider, for example, a hypothetical Web service
that provides information about books and music. Such a service should define
multiple resources, book, cd, review that are queried by title, author, or ISBN.
Example 1 in Fig. 2.1, example.org/book?title=zen represents a resource
for books that contain “zen” in the title. Examples 2 and 3 show how to query
the resource by author and ISBN. There are several options for defining resources
corresponding to a review. The system could have one review resource (as in 4a), a
dedicated resource for each product type (in 4b), or a composite resource (review)
with individual children resources, one per product type (4c). These all are valid
choices. Alternatively, as in Example 6, the URI structure can enforce a specific
order of parameters (type, then title, then author), thus making it unnecessary to
specify the type of each sub-element in the URI. Note that this format requires
implicit understanding of the structure of this URI, which is defined outside of the
URI by the provider of this Web service.
The problem of designing resources is similar to teaching object-oriented design
to programmers, who were first taught procedural languages – it requires a changed
mindset. One can define resources without deep understanding of REST, but it’s
unlikely that such design will take full advantage of all available features of HTTP
and URI standards as objects/classes. In the second step, the public methods of the
object are defined. In any non-trivial problem, these two steps identify many objects
and many methods. The application is built by connecting the objects, which invoke
methods on one another. A similar approach can be applied to defining resources,
except that only the first step identifies many objects (i.e. resources). The available
HTTP methods are defined in the standard and links between resources are traversed
at run-time. Thus steps 2 and 3 come for free in HTTP, but only if step 1 is done well.
44 P. Adamczyk et al.
Representations
Self-descriptive Messages
1
GET sends data from the server to the client, in the response. POST sends the data from the client
to the server, in the request. Thus, GET is used for reading, and POST for writing.
2
A simple bank transaction, e.g. transferring $100 from savings to checking, involves sending
four HTTP requests. First, create a resource for the transfer using POST. Next, send a PUT to the
2 REST and Web Services: In Theory and in Practice 45
to encode more complex operations (such as “search”) into URIs in RPC style even
though they know that it violates REST. Another reason why the CRUD metaphor
is not a good match is that HTTP methods POST and PUT do not map exactly to
CRUD’s “create” and “update,” respectively. PUT carries a representation produced
by the client, which the server should use to replace its contents (so it serves as both
create and update). POST means the server decides how to use the representation
submitted by the client in order to update its resource.
This problem of not taking full advantage of HTTP methods is not unique to Web
services. Typical Web applications (accessible via browsers) use only two HTTP
methods in practice. In a study of HTTP compliance of Web servers (Adamczyk
et al. 2007), we found that Web servers and intermediaries understand correctly
only GET and POST methods. Only a fraction of popular websites send compliant
responses to other HTTP methods, even though the popular Web servers implement
all these methods correctly. These compliance results haven’t changed much since
HTTP/1.1 standard has been released, in 1999.
The inclusion of the 4 HTTP methods corresponding to CRUD operations in a
definition of a RESTful service is only a first step in satisfying the principle of self-
describing messages. This principle means that methods should be used according
to their standard definitions. A case in point is the new HTTP method, PATCH,
added in March 2010 (Dusseault and Snell 2010). It is intended to complement
PUT and replace some uses of POST with more precise semantics. With POST, the
client cannot specify how the resource is to be updated. Unfortunately, the definition
of PATCH does not define the structure for including the instructions to update
(i.e., patch) the resource. A standard definition of the instructions will be necessary
to make this method interoperable. As the additions of PATCH indicates, the set
of relevant HTTP methods is not static. The WebDAV protocol (which RESTful
proponents tend to overlook) defines 8 more methods for distributed authoring and
manipulating collections of resources (Goland et al. 1999). Thus RESTful Web
services have many self-describing methods to choose from. Although today most
Web services don’t use their HTTP methods right, we hope that in time they will.
HATEOAS
Hypermedia as the engine of application state means that neither client nor server
needs to keep the state of the exchange in a session, because all the necessary
information is stored in the exchanged HTTP messages (in the URI and the
accompanying HTTP headers and body). Defining self-contained links is critical for
RESTful Web services, because these links make it possible to traverse, discover,
and connect to other services and applications.
resource specifying the withdrawal of $100 from savings. Then, send a second PUT to deposit
$100 to checking. Finally, send a PUT to commit the transaction. Note that the burden of verifying
that each step was successful is on the client. If a step fails, the client needs to send a DELETE to
the transaction resource to abort the transaction (Richardson and Ruby 2007).
46 P. Adamczyk et al.
The HTTP standard defines the meaning of different error conditions and several
mechanisms for caching. Compliant RESTful Web services should follow them.
Initially, RESTful services copied their error-handling mechanism from SOAP.
Many Web services would not use HTTP status codes (e.g. “404 Not Found”)
to describe the result of a request, but rather always returns “200 OK” with the
actual status is hidden in the response body. Other services (e.g. earlier versions of
Yahoo Web services) defined their own status codes that were incompatible with
the standard ones. By using service-specific codes, they would not take advantage
of existing Web systems that understand these codes thus forcing clients to build
specialized, non-interoperable software to handle them. Fortunately, most Web
services we surveyed now do use HTTP status codes, and only add service-specific
extensions for new statuses. For example, Delicious uses codes 500 and 999 to
indicate that user request was throttled (due to exceeding a pre-defined limit of
connections). HTTP does not have a status that corresponds to this condition, so
it makes sense to define a new one.
Our survey gathered little information about caching. Aside from exceptional
Web services like S3 (and even they don’t use the term caching in the documen-
tation), RESTful services do not document if they support caching. Of course, the
services that employ user-ids could not benefit from caching anyway.
As the length of this section indicates, RESTful services still have difficulty in
following the principles of REST. There are few fully compliant service definitions,
but it’s easy to find examples of services that violate any of the principles. On the
bright side, we have observed a lot of improvements in compliance over the last
few years. RESTful services, by the virtue of being public are more open to general
2 REST and Web Services: In Theory and in Practice 47
scrutiny. Users can discuss the design decisions in the open, criticize them, and see
changes in the next version. To gain a better perspective of the positive changes that
occurred over the years, the reader is encouraged to browse the discussion of these
and other violations documented at RESTWiki (2011).
An important question is: Why are many services that attempt to be RESTful not
compliant with the principles of REST? Are these principles too restrictive? Too
hard to implement? Unnecessary for Web services (as opposed to Web pages and
Web applications)? It’s still too early to tell.
Many frameworks and tools for building RESTful Web services are available today.
They are written in different programming languages and range from simple to
quite sophisticated in their support of HTTP and other Web technologies. As they
continue to improve, misunderstandings and violations present in today’s Web
services will likely lessen.
We have examined ten popular frameworks that provide automated support for
building software according to the principles of REST. Some frameworks, like
Ruby on Rails and Spring are generic Web frameworks, while others are specific
to RESTful services. Table 2.2 summarizes key features of these frameworks,
grouped by REST principles. The frameworks are listed alphabetically, sorted by the
programming language and name. The second column in the table shows how these
frameworks support defining resources (corresponding to REST principles 1 and 4).
Almost all the frameworks provide some support for building resources (URIs) and
hyperlinks – through URI templates (Gregorio et al. 2010), annotations in the target
programming language, or other types of mappings. The third column shows which
types of multimedia are supported and how (principle 3). Most frameworks enable
generation of multiple representation formats. The fourth column shows which
HTTP methods are supported (principle 4). Most of them support GET, POST, PUT,
and DELETE HTTP methods, either directly, or by specifying the desired method in
an auxiliary parameter [such as the X-HTTP-Method Override header, or the
hidden “ method” form field (Richardson and Ruby 2007)]. The last column points
out other interesting features provided by the frameworks. Few brave frameworks
have ventured into implementing more advanced concepts of caching, automated
testing, or authentication.
48
Table 2.2 How frameworks for building RESTful Web services support the principles of REST
Other (API,
Name (Prog. Resources and caching, status
language) HATEOAS Representation Messages codes, etc.)
Jersey (Java) Annotations for URI MIME types, XML, GET POST PUT Support for JAX-RS. Testing
mappings JSON and Atom DELETE framework
RESTEasy (Java) Annotations for URI Annotations for output GET POST PUT Output caching and
translations and representations (many DELETE compression Support for
variable mapping types supported). JAX-RS
Content negotiation
Restlet (Java) URI templates and Supports various output GET POST PUT Support for JAX-RS.
variable binding representations DELETE Caching headers set in
Conditions class.
Security checks added
via filters. All HTTP
status codes
Spring (Java) Templated URIs using Content negotiation with GET and POST ETag header for caching
Java annotations Accept header or by directly, PUT
URL inspection (read and DELETE
file extension) with
_method
Recess (PHP) URI templates and Not supported GET POST PUT Not supported
variable extraction DELETE
using annotations
Routes (Python) Proper URL syntax; Not supported GET POST PUT Not supported
No IDs in query DELETE
P. Adamczyk et al.
parameters
CherryPy (Python) Simple mapping: HTML forms GET and An object tree generated to
HTML forms POST map requests to Python
to Python variables functions
Django (Python) URI templates for Targeted output GET POST Caching. HTTP status codes
mapping advanced formats: XML, JSON, PUT supported by Python
URL patterns to YAML DELETE libraries
Python code
RESTfulie (Ruby, emphasizes many formats; content GET POST HTTP status codes;
Java) hypermedia negotiation PUT integrates with Ruby on
links DELETE Rails
Ruby on Rails Route configs map URI Excellent support of GET POST Conditional GET for caching
(Ruby) to Component many data formats – PUT RESTful authentication
class (imposes URI e.g. Accept header DELETE
conventions)
2 REST and Web Services: In Theory and in Practice
49
50 P. Adamczyk et al.
Several of the Java frameworks support JAX-RS, a Java API for RESTful Web
services. They are Jersey (considered the reference implementation), Restlet, and
RESTEasy. JAX-RS specifies how to map Java classes to Web resources using Java
annotations. The annotations specify the relative path of the resource (part of the
URI) for a Java class, which Java methods correspond to HTTP methods, which
media types are accepted by the class, and how to map class properties to selected
HTTP headers (Hadley and Sandoz 2009).
Aside from Django, all the Python and PHP frameworks offer only rudimentary
support for REST. Other frameworks include more advanced features, but they still
fall short of supporting all principles of REST. Most frameworks define schemes
for mapping URIs to classes and methods, but not all of them are as flexible as
HTTP requires, e.g. Ruby on Rails imposes constraints on URI formats. Only one
framework (Restlet) supports all HTTP status codes. No framework supports all
flavors of HTTP caching, and many do not support caching at all.
The principle of HATEOAS (unambiguous semantics for following and em-
bedding links) is not well supported. Only the RESTfulie framework emphasizes
the importance of this principle. Let’s consider a simple example of the expected
behavior. When a client requests a resource (e.g. information about a collection
of items) it should be easy to construct a URI to refer to an individual item from
that collection. Frameworks should provide built-in support for such conversions of
URIs. Currently, this mapping work must be implemented manually in the client
code, because most frameworks do not support it.
Overall, the RESTful frameworks need to include more functionality to be fully
compliant with REST. But the biggest problem is that even if they do implement
the support for a principle, the frameworks have no mechanisms to enforce that it is
applied correctly in the client code.
Frameworks make it possible to build bigger Web services, and their capabilities
keep on growing. Is that enough to persuade enterprise system architects to switch
to RESTful Web services? Recall the study of Web services by Pautasso et al.
(2008) we discussed in “Web Services in Theory”. They cite security, reliable
messaging and transactions as key differentiators between RESTful and WS–
services. To be ready for enterprise, RESTful frameworks need to support these
features. Richardson and Ruby (2007) show how these concepts can be implemented
using HTTP.
For basic message-level security, it’s enough to use HTTPS. But more complex
capabilities such as signatures, encryption, or federation (enabling a third party to
broker trust of identities) cannot be supplied by HTTP alone. Further research is
required to define these concepts properly in RESTful Web services (more about
this in “Open Research Problems of RESTful Services”.)
2 REST and Web Services: In Theory and in Practice 51
To provide reliable messaging, one needs to ensure that all HTTP methods are
idempotent. This property makes it possible to replay any method, as necessary,
to make sure that it succeeded. Of course, this approach to reliable messaging is
tedious and currently requires a lot of manual coding on the client side.
Implementing transactions with HTTP messages requires exchanging many
messages, which can get complex quickly (as we saw in “Self-descriptive Mes-
sages”). Current frameworks are not mature enough to abstract out/encapsulate
common transaction patterns. But transactions are needed as building blocks of
workflows, which occur often in enterprise systems. A proposed extension to the
Jersey framework introduces action resources for specifying workflows (Hadley
et al. 2010). Each action resource exposes one workflow operation available on
the service. The client obtains the workflow specification (i.e. the list of action
resources) at the beginning of the sequence. In line with the principle of HATEOAS,
it’s the client’s responsibility to keep track of the current state of the system
throughout the execution in order to invoke the workflow resources in the correct
order. This is a dynamic approach, because the exact sequence of the workflow
need not be specified until the client begins to execute it.
But even if security, reliable messaging, and transactions are solved successfully,
RESTful services must also demonstrate scalability. Compared to large legacy
systems on top of which many WS– services are built, current RESTful services
are small. Tool support is needed for combining disparate services to build larger
ones and for automating the generation of URI schemas that can adapt when a
service is being extended.
Today’s frameworks are not yet ready to support enterprise needs. They do
not implement advanced security features or transactions; they do not verify that
HTTP methods they generate are idempotent, which is the necessary prerequisite
for reliable messaging; they are not scalable. Implementing these features is a
matter of time, because HTTP already defines most of the necessary concepts to
perform these tasks. However, it’s not enough that the frameworks implement the
necessary functionality. The frameworks must guide and force the users to recognize
the correct features for the job and to apply them correctly.
Proponents of RESTful Web services made their first attempts to reach the
research community via conference presentations (Prescod 2002; Haas 2005),
and computer magazine editorials (Vinoski 2008). Recently, survey papers
(Pautasso et al. 2008), and new research work (Pautasso et al. 2010; Overdick 2007)
began to appear. Hopefully, this book will advance the state of research even farther.
The problems we discuss below are concerned with non-functional requirements
and how they can be supported by RESTful services. Many of these research efforts
are defining new Web standards. Web linking (Nottingham 2010) aims to improve
cache invalidation. HTTP PATCH (Dusseault and Snell 2010) defines a new method
to make more maintainable services. URI templates (Gregorio et al. 2010) make
it easier to define groups of resources with regular expressions. OAuth (Hammer-
Lahav 2010) secures authentication and data sharing in HTTP-based systems.
Caching
Maintainability
Typical maintenance tasks of Web services (adding new features, fixing service
APIs) affect services themselves, their documentation, the client code, and even
the development tools. Since RESTful Web services are still prone to wholesale
changes, each of these facets offers ample opportunities for research.
2 REST and Web Services: In Theory and in Practice 53
Changes of Web service definitions necessitate upgrades of the client code. When
a new version of a service becomes available, clients need to adapt their code.
Neither WS– nor RESTful services providers are concerned with making client
updates easier. They claim that there is no need to deprecate APIs, because they
will always be available, so clients are not required to upgrade. Ideally, this would
be the case, because well-named resources do not need to change (Berners-Lee
2011). New Web services might be able to preserve their APIs for some time, but
maintaining several versions isn’t realistic if a service plans to grow. Some services
offer software development tools for building client applications, but they suffer
from the same types of challenges as typical software – APIs change. Is it time to
start exploring refactoring of Web service APIs?
Storing URIs in web logs may lead to privacy problems if the logs are not
protected and anonymized. WS– services do not store sensitive data in HTTP
method signature and query strings. On the other hand, URIs created for RESTful
Web services become the audit trail, and they should be anonymized.
Figure 2.2 illustrates a hypothetical model of how the security and privacy
measures can be applied together. It shows a secure token service, a key entity in
a third party authentication model. Note that the figure does not define the actual
steps of an ideal protocol; it is an open research problem. Researchers also need to
figure out how the security measures fit the REST model.
QoS
When multiple providers offer the same service, a client has a choice and can select
the most suitable one. Often, this choice comes down to the Quality of Service
(QoS) parameters. RESTful Web services today ignore QoS requirements; their
only concern is providing functional interfaces. To add QoS parameters to RESTful
services, a language for describing the parameters and a mechanism to incorporate
the description in the HTTP payload is needed. Defining a standard QoS description
language might benefit from the work in Semantic Web. Semantic Web ontologies
define standard ways of interpreting information, such as QoS parameters, enabling
all clients to interpret them the same way.
2 REST and Web Services: In Theory and in Practice 55
Web services are good candidates for studying how software engineering concepts
are followed in large, publicly available systems. But there have been few successful
studies of RESTful services, or side-by-side comparisons of a service that exposes
two interfaces defined in the competing styles (one RESTful, one WS–).
It is not easy to compare these two styles at the level of principles. The first
order of research is to identify good principles for making the comparison. Zarras
(2004) identifies the following principles for comparing middleware infrastructures:
openness, scalability, performance, and distribution transparency. Properties of
software architectures (Bass et al. 2002) is another source of principles to consider.
Another possibility is to apply the same principled approach Fielding used to derive
REST in order to define both RESTful and WS– architectural styles. This would
entail selecting and applying additional constraints, one at a time, to derive complete
definitions of both architectural styles.
Conclusion
RESTful Web services (and Web services in general) pose the first serious test of
the principles of REST, as identified by Fielding. On the one hand, the emergence
of RESTful Web services, in response to WS– services can serve as an indication
that REST is the correct architecture for the Web. On the other hand, the state of
practice still shows gaps in understanding and applying the theory behind REST,
thus indicating that the process is not complete.
Up until a few years ago, there was a simple dichotomy between REST
and WS–. RESTful services were used only for simple, public services. In
contrast, enterprise standards, tools vendors, and the research community were only
concerned with WS– services. This is no longer the case – both styles are being
used in all domains. The new challenge is to use them correctly, and to be able
to align them to solve the real problems of the enterprise. Can RESTful services
scale up to the enterprise-size challenges? We believe so. Amazon, Google, Yahoo,
Microsoft, and other big companies have been building large, scalable, extensible,
and relatively secure systems on the Web. RESTful services have the same basic
principles to follow.
This concludes our whirlwind overview of how Web services relate to REST, in
theory and in practice. Other chapters in this book will explore these topics in more
details.
Acknowledgements The authors would like to thank Nicholas Chen, Hakan Erdogmus, Jim
Webber, and anonymous reviewers for reviewing earlier drafts of this work.
56 P. Adamczyk et al.
References
L. Bass and P. Clementes and R. Kazman. Software Architecture in Practice, 2nd Edition. Addison
Wesley, 2002.
P. Adamczyk, M. Hafiz, and R. Johnson. Non-compliant and Proud: A Case Study of HTTP
Compliance, DCS-R-2935. Technical report, University of Illinois, 2007.
Amazon. Amazon Simple Storage Service API Reference, May 2011. http://docs.
amazonwebservices.com/AmazonS3/latest/API/
Apache HTTP Server v2.2. Authentication, authorization and access control, May 2011. http://
httpd.apache.org/docs/2.2/howto/auth.html.
T. Berners-Lee. Cool URIs don’t change, May 2011. http://www.w3.org/Provider/Style/URI.html.
T. Berners-Lee, R. Fielding, and H. Frystyk. RFC 1945: Hypertext Transfer Protocol — HTTP/1.0,
May 1996.
J. Correia and M. Cantara. Gartner sheds light on developer opps in web services. Integration
Developers News, June 2003.
Dare Obsanjo Blog. Misunderstanding REST: A look at the Bloglines, del.icio.us and Flickr APIs,
May 2011. http://www.25hoursaday.com/weblog/PermaLink.aspx?guid=7a2f3df2-83f7-471b-
bbe6-2d8462060263.
B. M. Duska, D. Marwood, and M. J. Freeley. The measured access characteristics of World-Wide-
Web client proxy caches. In USENIX Symposium on Internet Technologies and Systems, USITS,
1997.
L. Dusseault and J. Snell. RFC 5789: PATCH Method for HTTP, Mar. 2010.
J. Fan and S. Kambhampati. A Snapshot of Public Web Services. In SIGMOD Record, Vol. 34, No.
1, Mar. 2005.
R. Fielding. Architectural Styles and the Design of Network-based Software Architectures.
Doctoral dissertation. Technical report, University of California, Irvine, 2000.
R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and T. Berners-Lee. RFC 2616:
Hypertext Transfer Protocol — HTTP/1.1, June 1999.
B. Fitzpatrick. OpenID, 2005. http://openid.net/.
J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A. Luotonen, and L. Stewart. RFC
2617: HTTP Authentication: Basic and Digest Access Authentication, June 1999.
J. Garrett. Ajax: A New Approach to Web Applications, Feb. 2005. http://adaptivepath.com/ideas/
essays/archives/000385.php.
Y. Goland, E. J. Whitehead, A. Faizi, S. Carter, and D. Jensen. HTTP Extensions for Distributed
Authoring WebDAV. Internet proposed standard RFC 2518, Feb. 1999.
J. Gregorio, R. Fielding, M. Hadley, and M. Nottingham. URI Template (draft), Mar. 2010.
H. Haas. Reconciling Web services and REST services (Keynote Address). In 3rd IEEE European
Conference on Web Services (ECOWS 2005), Nov. 2005.
M. Hadley, S. Pericas-Geertsen, and P. Sandoz. Exploring Hypermedia Support in Jersey. In WS-
REST 2010, Apr. 2010.
M. Hadley and P. Sandoz. JAX-RS: Java API for RESTful Web Services (version 1.1), Sept. 2009.
E. Hammer-Lahav. RFC 5849: The OAuth 1.0 Protocol, Apr. 2010.
I. Hickson. HTML5: A vocabulary and associated APIs for HTML and XHTML, Oct. 2010.
Joe McKendrick. Service Oriented Blog, May 2011. http://www.zdnet.com/blog/service-oriented/?
p0542.
H. Kilov. From semantic to object-oriented data modeling. In First International Conference on
Systems Integration, pages 385–393, 1990.
S. M. Kim and M. Rosu. A Survey of Public Web Services. In WWW 2004, 2004.
L. Richardson and S. Ruby. RESTful Web Services. O’Reilly, Oct. 2007.
M. Nottingham. HTTP Status Report. In QCon, Apr. 2009.
Meebo Dev Blog. Introducing XAuth, Apr. 2010. http://blog.meebo.com/?p=2391.
M. Nottingham. Web Linking (draft), May 2010.
H. Overdick. Towards resource-oriented BPEL. In C. Pautasso and T. Gschwind, editors, WEWST,
volume 313. CEUR-WS.org, 2007.
2 REST and Web Services: In Theory and in Practice 57
C. Pautasso, E. Wilde, and A. Marinos. First International Workshop on RESTful Design (WS-
REST 2010), Apr. 2010.
C. Pautasso, O. Zimmermann, and F. Leymann. RESTful Web Services vs. “Big” Web Services:
Making the Right Architectural Decision. In WWW ’08: Proceeding of the 17th international
conference on World Wide Web, pages 805–814, New York, NY, USA, 2008. ACM.
P. Prescod. Roots of the REST/SOAP Debate. In Extreme Markup Languages, EML, 2002.
E. Rescorla. RFC 2818: HTTP over TLS, May 2000.
RESTWiki, May 2011. http://rest.blueoxen.net/cgi-bin/wiki.pl.
D. Sholler. 2008 SOA User Survey: Adoption Trends and Characteristics, Sept. 2008.
S. Vinoski. Serendipitous reuse. IEEE Internet Computing, 12(1):84–87, 2008.
W3C Working Group Note. Web Services Architecture, May 2011. http://www.w3.org/TR/2004/
NOTE-ws-arch-20040211/.
Web Service Security (WSS). Web Services Security: SOAP Message Security 1.1, Feb. 2006.
A. Zarras. A comparison framework for middleware infrastructures. Journal of Object Technology,
3(5):103–123, 2004.
Part II
Design
Chapter 3
RESTful Domain Application Protocols
Ian Robinson
Introduction
This chapter reflects the concerns of systems architects and developers charged with
satisfying specific business needs – with getting things done. REST’s hypermedia
constraint (Fielding 2000) is all about getting things done: at the heart of the
constraint is a compact of application, application protocol and application state
that addresses the need to do useful things with computerized behaviors, to effect
the kinds of changes in application state that release value to the providers and
consumers of a business capability.
From an analytical perspective, every useful application of computerized be-
havior can be said to evidence what I call an underlying domain application
protocol – much as every meaningful utterance evidences an underlying natural-
language grammar. The design strategies I present in this chapter represent acts of
deliberate discovery through which we come to understand the domain protocols
behind specific, domain-sensitive applications of computerized behavior.
I. Robinson ()
Neo Technology, Menlo Park, CA, USA
e-mail: [email protected]
To answer this question, consider the business process shown in Fig. 3.1.
Figure 3.1 illustrates the sequence of interactions that must take place for a
customer to purchase some goods from a supplier.1 The customer asks the supplier
for a quote. On receiving a quote, the customer decides to order the goods for which
they have been quoted. Once the supplier has confirmed the order, the customer pays
for the goods, or cancels the order.
1
This example simplifies the set of interactions encountered in a real-world application in order to
highlight the key points in protocol design.
3 RESTful Domain Application Protocols 63
Request Quote
Order Goods
Confirm Order
Customer Supplier
Cancel
Pay
Imagine that we have been charged with exposing this procurement process to
third parties over the Web. A specific business need – the desire to allow customers
to order and pay for goods – motivates a specific engineering task: that of exposing
our quoting, order processing and payment functions in a way that allows customers
to execute and complete our procurement process in a repeatable, well-understood
manner. At the same time, however, we must remain mindful of the fact that other
applications may wish to reuse parts of our system for entirely different purposes.
Despite having been motivated by the specific business need behind this first project,
we do not want to overly specialise our systems’ interfaces; rather, we want to
implement our APIs in ways that allow them to be composed into other applications
and processes.
Fast forward to a time when we’ve built and deployed a solution to meet
our business’ procurement needs, and a client has just successfully completed an
instance of our procurement process. In order to reach the successful conclusion of
the process, the client had to initiate a series of legitimate interactions with whatever
systems we’d chosen to expose over the network. The successful completion of the
process implies the effective existence of a domain application protocol, a set of
rules and conventions through which participants in a distributed system coordinate
their interactions to achieve a useful, domain-specific application goal.
In the context of a RESTful web application, a domain application protocol is
an abstraction of the media types, link relations, and HTTP idioms necessary to
achieve a particular application goal. The design of a domain application protocol
incorporates the deliberate discovery activities necessary to describe a RESTful
API in terms of specific media types and links relations, plus a context-sensitive
narrowing of HTTP.
Application
Application State
A domain application protocol is the set of rules and conventions that guides and
constrains the interactions between participants in a distributed application.2 By
adhering to a protocol, participants achieve a useful domain or business outcome.
Revisiting our definition of application, we can say that an application is an instance
of the execution of a protocol. In executing the protocol, the participants create an
application, which in turn achieves an application goal.
To achieve an application goal in the context of a RESTful web application, a
client progressively interacts with a community of resources. These resources can
be hosted and governed by a single server, or they can be distributed across the
network. Either way, every resource implements the same uniform interface, which
in the case of a web application is HTTP.
2
The term “domain application protocol” and the three-step design methodology described here
were first proposed in Webber et al. (2010). We chose the term “domain application protocol” so
as to align it both with the book’s focus on automating business (domain) processes, and with
our use of the terms “application” and “application state.” A domain application protocol is more
commonly referred to as a coordination protocol: see, for example, Alonso et al. (2004).
3 RESTful Domain Application Protocols 65
Design Steps
3
See Chap. 5, “Hypermedia Types,” for a more thorough, and more nuanced, discussion of
hypermedia control capabilities.
66 I. Robinson
protocol, albeit a very simple one. Most CRUD-based data services are designed and
implemented without reference to the underlying domain application protocol. This
doesn’t, however, mean that there isn’t a protocol – only that we haven’t modelled
it explicitly. Every application is an instance of a protocol, no matter how simple or
implicit.
Whereas Step 1 is optional, Steps 2 and 3 usually proceed iteratively and in
parallel. We start by identifying a number of candidate resources, and then detail
the HTTP interactions through which a client manipulates representations of these
resources. In working through these interactions, we discover additional resources
that help adapt the domain to the goals expressed in the protocol. In the worked
scenario later in this chapter, for example, we discover some forms-based resources;
these resources allow a client to request a quote, submit an order, and cancel an
order.
Step 1
Step 2
On the server side, a RESTful web application is based around resources and
resource life cycles.
3 RESTful Domain Application Protocols 67
request quote
Quote Requested
order goods
Goods Ordered
confirm order
Order Confirmed
pay cancel
Paid Cancelled
Resources
the structure by applying some of this data back to the network through the uniform
interface. Applying the data – operating a link or form – only partially completes
the structure; more often than not, it reveals yet more links and forms.
By emphasizing the resource’s role in adapting server capabilities for con-
sumption by network-oriented clients, we address one of the downsides of the
server-centric perspective, which is the tendency to treat resources in terms of
a relatively closed set of domain entities, coarsely manipulated through a small
set of verbs. While suitable for simple CRUD-based data services, this entity-
oriented attitude to building RESTful systems fails to address the needs of more
sophisticated processes. The protocol perspective suggests that resources do not
map directly to domain entities; rather, they serve to adapt the domain for its partial
application through hypermedia and the uniform interface. Adapting a domain for
consumption by a hypermedia client results in our identifying more resources than
would normally be identified through a domain-entity-oriented approach. From the
client’s point of view, domain (i.e. business) behaviors emerge as a side effect
of applying a relatively closed set of document-oriented verbs to this open set of
resources.
Resource State
A resource has state, and this state, much like application state, can have its own
lifecycle. But whereas application state lends integrity to a sequence of interactions
with multiple resources, resource state is concerned solely with the state of an
individual resource. This resource state is governed and maintained by the server
hosting the resource. Attempts to manipulate a resource’s state representations must
conform to the business rules the server uses to govern the lifecycle of the resource.
Such business rules are private to the server and should never be exposed to clients.
For most resources, a resource’s state is simply a function of its data. For some
resources, however, a resource’s state is also partly a function of the state of other
resources with which the resource is associated through some server-governed rules.
For example, the state of an order is partly a function of the state of any payment
with which that order has been associated by the server hosting the order. As with
any other business rules governing the state of a resource, these rules remain hidden
behind the RESTful interface.
Servers, then, are responsible for maintaining resource state, not application
state. Application state remains significant, however. The overall distributed appli-
cation still moves through several different application states. What’s important is
that the application state model (and the corresponding protocol) is nowhere reified
on the server side. Changes to the state of the overall distributed application emerge
as a side effect of the client manipulating the states of individual resources through
their representations.
Through interacting with a community of resources, a client progressively
realizes an application goal in accordance with an implicit domain application
protocol. Some client interactions retrieve representations of resource state, others
3 RESTful Domain Application Protocols 69
Hypermedia
Step 3
A RESTful API is documented using media types, link relations and HTTP idioms.
Media Types
The Atom Syndication Format (Nottingham and Sayre 2005), for example, includes
all these elements. In terms of representation format, Atom is based on XML. With
regard to schemas, the Atom specification includes two RELAX NG schemas:
one for feeds, another for entries. To these it adds a processing model, which
determines how content, foreign mark-up and extensions to the Atom vocabulary
should be interpreted. In terms of its hypermedia capabilities, it identifies the
<atom:link> element as a hypermedia control, and defines five link relation
values (alternate, related, self, enclosure, and via) with which links can be annotated
with semantic context. The Atom Syndication Format interpretative scheme is
keyed off the application/atomCxml value in Content-Type request and
response headers.
Link Relations
On the human web, we intuitively understand what links and forms mean based on
the context in which they appear. Machines, on the other hand, cannot reliably infer
such implicit semantics. In order to help machine clients decide which hypermedia
control to activate in a received resource representation, we must provide some
additional, explicit semantics. One of the most popular ways of adding semantic
context to hypermedia controls is to annotate links with link relations.
Link relations describe the purpose of a link, the meaning of a target resource,
or the relationship between a link’s context and the target resource. By stating the
purpose of a link, a link relation helps a client use the link according to its purpose.
The semantic range of a link relation can vary from describing how the current
link’s context is related to another resource, to indicating that the target resource
has particular attributes or behaviors.
HTML defined the rel attribute for annotating both anchor and link elements
with link relations. This attribute convention was adopted by several other formats,
including the Atom Syndication Format. Links that have been annotated with a link
relation value are called typed links.
Figure. 3.3 shows a typed link taken from the example later in this chapter. The
link has been typed with the link relation value rb:order. This value acts as a key
into a semantic. In this instance, the associated semantic indicates that the linked or
destination resource is an order.
Link relations come in one of two flavors: registered and extension (Nottingham
2010). Registered relations are registered with IANA’s Link Relation Type registry
(Link Relations 2011). Such well-defined link types take the form of simple string
tokens. Examples of registered relation types include self and payment. Extension
3 RESTful Domain Application Protocols 71
relations, on the other hand, are types that have not been registered with IANA.
Such relations are often proprietary to an organisation or application. In order to
disambiguate them from any similarly named relations elsewhere, they take the form
of a URI. The link relation shown in Fig. 3.3 is an extension relation. It has been
formatted as a compact URI (Birbeck and McCarron 2009); expanding the URI
returns the absolute link relation value http://relations.restbucks.com/order.
Documenting a Protocol
HTTP Idioms
effectively “programs” the client on the fly. The advantage of the inline approach is
that it makes it easier to evolve and extend an application over time.
Here are some of the ways we can use HTTP headers, status codes and entity
body control data to describe at runtime which HTTP idioms a client should use to
manipulate resource representations:
• Cache-Control directives instruct intermediaries to cache content in accor-
dance with HTTP’s caching rules.
• Forms (HTML, XForms, etc.) program clients with control data (such as a URI,
HTTP verb, and required Content-Type value), which the client can then use
to encode and submit the form.
• ETag headers indicate to the client that subsequent requests for the same
resource should use a conditional idiom: either a conditional GET, which uses
an If-None-Match header with an entity tag value to instruct the server to
return a full-blown response only if the resource addressed in the request has
changed since the entity tag value was issued; or a conditional PUT, POST or
DELETE, which uses an If-None header with an entity tag value to instruct the
server to apply the request if and only if the resource addressed in the request has
not changed since the entity tag value was issued.
• Some of the HTTP status codes determine the next HTTP idiom to be used; 303
See Other, for example, instructs the client to issue a GET request for the
resource specified in the accompanying Location header.
• 405 Method Not Allowed tells the client that the verb in the request
cannot be used; issuing an OPTIONS request for the same resource will return a
200 OK response with an Allow header specifying which verbs can be used.
4
Restbucks served as the basis for the examples in Webber et al. (2010).
3 RESTful Domain Application Protocols 73
Start
Every application needs at least one entry point, located at a well-known URI,
through which a client can initiate a sequence of interactions – and our procurement
application is no different. To start the application, clients navigate to http://
restbucks.com/shop, as shown in Fig. 3.4.
The response shown in Fig. 3.4 includes two headers of note: Cache-Control
and Content-Type.
The Cache-Control header influences the behavior of any caching interme-
diaries – local caches, proxies, and reverse proxies – along the request–response
path. Caching allows us to store copies of a representation closer to clients,
thereby helping to conserve bandwidth, reduce latency, and minimize load on the
origin server. In this instance, the header includes two directives: public, which
74 I. Robinson
GET /shop
Started
rb:rfq
makes the response cacheable by all intermediaries, both private and shared; and
max-ageD86400, which indicates that the response will remain fresh for up to
one day after it was issued by the origin server. Together, these two directives ensure
that the majority of requests for the procurement “homepage” are satisfied by the
caching infrastructure, rather than by the origin server.
The response’s Content-Type header has a media type value of applica-
tion/restbucksCxml. This is a proprietary, but nonetheless reasonably gen-
eralized, format for representing quotes and orders; it is documented in more detail
at the end of this chapter.
Below the response header block is the entity body, comprising an XML-
formatted representation of the shop’s homepage. This entry-point resource repre-
sentation advertises the procurement application’s capabilities. It currently contains
a single <link> element. The link is typed rb:rfq, indicating that the resource at
the other end of the link allows the client to request a quote.
An entry-point resource such as this is the ideal place to advertise new ca-
pabilities. If, for example, we were to evolve our application to include search
functionality, we might advertise this new capability by adding a typed link (leading
to a search form) to the shop’s entry-point resource representation.
With this first client request, the overall distributed application enters the Started
state, as shown in Fig. 3.5.
Request Quote
Having started the application, the client now processes the shop representation. The
representation contains only one typed link, so to make forward progress, the client
issues a request for the request-for-quote form, as shown in Fig. 3.6.
3 RESTful Domain Application Protocols 75
The response shown in Fig. 3.6 contains an XForms form (Boyer 2009). XForms
is an XML vocabulary and data processing model for building web forms inside
a host application. It is based on a model-view-controller architecture. The form
shown in Fig. 3.6 uses an XForms <model> element to communicate control
data to the client. The <submission> element’s resource, method and
mediatype attributes specify the URI, HTTP method and Content-Type
header value to be used when submitting the form. The <model> element’s
schema attribute references an XML Schema instance to which the submitted
content must conform. A client programmed with the correct media type library and
appropriate HTTP and XForms processing capabilities can use this inline control
data to compose and submit its next request.
Note that the representation format used here doesn’t explicitly encode the
fact that this form allows the client to submit a request for a quote – there’s no
<request-for-quote> element, for example. This is because throughout our
procurement application we use a strategy of providing typed links to forms. The
link relation associated with a typed link establishes the meaning of the linked
resource. When dereferencing the link, the client retains this contextual knowledge
(in this instance, the client understands that the linked resource will allow it to
submit a request for a quote), and processes the received form accordingly. In doing
so, the client navigates a steady state space. Following the link doesn’t change the
state of the overall distributed application; it does, however, enrich that state. By
following a link to a form, the client discovers new opportunities – and appropriate
idioms – for progressing the application further.
The client “fills out” the form – that is, it creates a request whose body conforms
to the schema at http://schemas.restbucks.com/shop.xsd – and POSTs it to the URI
supplied in the control data, as shown in Fig. 3.7.
76 I. Robinson
Place Order
Assuming the quote is satisfactory, we can now observe what happens when the
client wants to place an order. First, the client follows the quote’s rb:order-form
typed link, as shown in Fig. 3.9. The response contains another XForms form,
similar to the one in Fig. 3.6. But whereas the form in Fig. 3.6 was empty, this one
has been pre-populated by the server.
The response’s Content-Location header indicates the source for this form
data. The header value refers back to the quote issued earlier in the application.
In other words, the entity encoded in the form is also accessible from another
location: http://restbucks.com/quotes/1234. The result is that we have two resources,
both of which share the same underlying domain data. The first adapts the domain
so that a client can receive representations of a quote. The second – the pre-filled
form – adapts the domain so that a hypermedia client can advance the procurement
protocol by submitting an order based on a previously received quote.
78 I. Robinson
Started
GET /request-for-quote
POST /quotes
Quote Requested
self rb:order-form
Location: http://restbucks.com/quotes/1234
Based on the quote data, the server responsible for this resource has generated
a form that can then be POSTed to an order processor. The form contains all the
information necessary to create an order, thereby eliminating any need for the order
processor to look up the original quote. But this strategy, useful as it is in making
the message self-sufficient, also raises an issue of message integrity, for the form’s
target need not be hosted on the same server – that is, the order processor may very
well belong in an entirely different subsystem. Because we’re passing around quote
data, rather than a reference to a quote, a malicious client might be tempted to adjust
the quote values prior to submitting the form, thereby earning itself a substantial
discount. Given this possibility, how can we prevent clients from tampering with
the message?
The solution we’ve adopted depends on the quoting and order processing
subsystems having established a shared key. Prior to sending the response, the
quotes resource generates a hash of the form data (the <shop> element and its
3 RESTful Domain Application Protocols 79
children) and signs the hash using this shared secret. It then appends the generated
value, together with its client ID, to the form URI, to make http://restbucks.com/
orders?c=99fe97e1&s=k2awEpciJkd2X8rt3NmgDg8AyUo%3D. On receiving the
POSTed form, the ordering subsystem is able to parse out the client ID and signed
hash, recalculate its own version of the signed hash, and compare the recalculated
value with the received value. 5
5
This is an example of a one-time URI. See Allamaraju (2010) for more details of generating
one-time URIs.
80 I. Robinson
Note that the design decisions we’ve made here trade message integrity for
increased coupling. The quotes resource and the order processor are coupled through
their sharing a secret to sign the hash, and through their sharing a URI tem-
plate, /orders?c=fclientIdg&s=fsignedHashValueg, to generate the
form URI. Moreover, if the shared secret leaks out, the tamper proofing mechanism
will have been compromised.
There is one final thing to note about the response shown in Fig. 3.9. Restbucks
has a business rule that says that a quote is valid for up to seven days after it has
been issued. As we can see from the quote response in Fig. 3.7, the quote that was
recently requested by the client was generated on Monday, 26 July 2010 at 10:01:00
GMT. The Expires header attached to the order form response indicates that the
form representation can be cached, and will remain fresh, for exactly seven days
from when the underlying quote was first issued.
To place its order, the client submits the form, as shown in Fig. 3.10. The
order processor responds with 202 Accepted, indicating that it has successfully
received the request but has not yet finished processing it. Both the Location
header and the typed link in the response body point to a resource that the client can
later interrogate to discover the eventual result of processing the request.
The 202 Accepted status code separates the action of accepting the request
from the work necessary to fulfil it. In doing so, it coordinates the successful transfer
of the request in the context of an asynchronous server-side task. To create an order
in its initial state, a number of potentially slow operations must take place behind the
RESTful interface. The order processor must contact a third-party payment provider
and set up a transaction (to be completed later by the client); it must also contact
the warehouse to determine stock availability. Both of these operations are relatively
slow. Rather than have the client hang onto a connection waiting for a response de-
scribing the outcome of all this work, we’ve chosen simply to acknowledge success-
ful delivery of the request while queuing the work itself for subsequent processing.
With this interaction, the client’s view of the state of the overall distributed
application changes from Quote Requested to Goods Ordered, as shown in Fig. 3.11.
Confirm Order
The client can now begin to poll the resource identified in the Location header
of the response shown in Fig. 3.10. In polling, the client becomes responsible
for the successful “delivery” of the outcome of its order request. (In contrast,
pub/sub solutions depend on either the publisher or a piece of middleware to deliver
notifications to subscribers successfully.) Figure. 3.12 shows the client’s first attempt
at polling the order at http://restbucks.com/orders/9876.
The server responds with 404 Not Found, indicating that the order has not
yet been created (the tasks necessary to create the order in its initial state have not
completed). The client waits a couple of seconds, and then tries again, as shown in
Fig. 3.13.
3 RESTful Domain Application Protocols 81
This time, all the server-side tasks necessary to create an order in its initial state
have been completed, so the server responds with a representation of the newly
created order. As the value of the order’s <status> element indicates, the order
is Awaiting Payment. This is resource state – and a particularly interesting kind of
resource state at that, for the state of this order is not only a function of the data
proper to the resource, it is also (partly) a function of the state of the payment with
which the order was associated when it was created. While the payment is waiting
to be completed by the client, this order is in the state of Awaiting Payment. The
82 I. Robinson
Quote Requested
GET /order-forms/1234
POST /orders?c=99fe97e1&s=k2awEpciJkd2X8rt3NmgDg8AyUo%3D
Goods Ordered
202 Accepted
Fig. 3.11 Application state changes from Quote Requested to Goods Ordered
server responsible for the order resource can “watch” the payment resource in order
to compute the state of the order.
The order’s resource state, then, can change over time; moreover, it can change
as a function of other resources changing state. This kind of situation requires us
to make some tradeoffs between consistency and efficient use of network resources.
The client here desires a view of the order consistent with the view held on the
server; we, however, as designers of a networked application, want to use caching
to conserve bandwidth, reduce latency, and save processing cycles.
3 RESTful Domain Application Protocols 83
Before we look at how a client or cache can use an entity tag value to maintain
consistency in a reasonably network-efficient manner, let’s examine the order’s
Cache-Control header. We’ve made the order resource representation cacheable
using a cache-but-revalidate strategy, implemented using two Cache-Control
directives. The first of these directives, public, makes the response cacheable
by all caches; the second, max-ageD0, indicates that the cached response must
immediately be treated as stale.
This cache-but-revalidate strategy provides consistency, but at the expense of
a small increase in network traffic. Anyone holding a copy of the order must
revalidate with the origin server with every request using a conditional GET.
Conditional GET requests look like normal GET requests, except they also include
an If-None-Match header, which takes a previously received entity tag as a
value. If the resource hasn’t changed since the supplied entity tag was generated,
the server responds 304 Not Modified, thereby allowing the requestor to use
its cached copy of the order. If the resource has changed since the supplied entity
tag value was generated, the origin server replies with a full-blown response. This
response travels all the way to the client, replacing any cached copies along the
response path as it does so.
Returning to the entity body, we see that it contains four typed links: two with
registered link relations (self and payment), and two with extension link relations
(rb:cancellation and rb:quote):
• The self link indicates the preferred URI for the order.
• The rb:quote link points back to the quote used to created the order.
• The rb:cancellation link points to a resource that allows the client to cancel the
order.
• The payment link refers to a resource that can be used to pay for the order.
With the transmission of the order response, the state of the overall distributed
application has changed from Goods Ordered to Order Confirmed, as shown in
Fig. 3.14.
Pay
Choosing now to pay for the order, the client GETs the payment typed link, as shown
in Fig. 3.15. This request is made over a secure channel to a third-party payment
provider.
The payment provider’s response comprises an XHTML form representation of
a payment waiting to be filled out with the client’s payment details. The client fills
out the form and POSTs it back to itself. The outcome of this POST request depends
on the current state of the payment. POSTing the client’s payment details back
to the payment resource for the first time changes the state of the payment from
Awaiting Payment to Paid, and causes the payment to return a 200 OK response, as
shown in Fig. 3.16. Once is in the Paid state, however, the payment will no longer
3 RESTful Domain Application Protocols 85
Goods Ordered
GET /orders/9876
Order Confirmed
rb:quote payment
self rb:cancellation
Fig. 3.14 Application state changes from Goods Ordered to Order Confirmed
accept POST requests; subsequent POST requests will cause the resource to return a
405 Method Not Allowed response instead. In effect, the payment resource
implements idempotent POST; that is, multiple POSTs to the payment cause the
transaction to be completed only once.
The response shown in Fig. 3.16 comprises another form. When the order
processor set up the payment, it supplied the payment provider with a callback URI
and confirmation ID. The payment provider uses these details to create a pre-filled
payment confirmation form, which the client now submits, as shown in Fig. 3.17.
The resource to which the form data is POSTed validates the received con-
firmation ID and sets the state of the underlying order domain entity to Paid. It
then redirects the client to the order resource with a 303 See Other response.
As shown in Fig. 3.18, the client makes a GET request of the URI supplied in the
redirect’s Location header.
86 I. Robinson
When following the redirect to the order, the client adds the entity tag value it
received the last time it requested the order to an If-None-Match request header,
thereby making the request conditional. This conditional request requires the server
to return a full-blown response only if the entity tag associated with the requested
entity differs from the entity tag value supplied in the request. Because the order
has changed since the client last requested it (its resource state has changed from
Awaiting Payment to Paid, and therefore its entity tag value is different), the server
returns a full response. This response includes a new entity tag value.
With this last series of interactions, the payment’s state has changed to Paid, as
has the order’s. And with these two resource state changes, the client’s view of the
overall distributed application’s state has changed from Order Confirmed to Paid, as
shown in Fig. 3.19. The procurement application has reached a terminal state.
Cancel
Instead of paying for an order, a client may choose to cancel it. (In a real-world
application there would likely be several points where the client could choose
to cancel the order.) Following a link typed with rb:cancellation leads the client
to a form, which the client then uses to PUT a reason for cancelling the order
3 RESTful Domain Application Protocols 87
GET https://example.org/payments/1010
Order Confirmed
POST https://example.org/
payments/1010
POST /payments/9876
GET /orders/9876
Paid
rb:quote self
References
Paul Prescod. Roots of the REST/SOAP Debate, 2002 Extreme Markup Languages Conference,
Montréal, Canada, Aug 2002.
The Sun Cloud API. 2009. http://kenai.com/projects/suncloudapis/pages/Home.
Jim Webber, Savas Parastatidis, and Ian Robinson. REST in Practice: Hypermedia and Systems
Architecture. O’Reilly, 2010.
Chapter 4
Hypermedia Types
Mike Amundsen
Introduction
M. Amundsen ()
Erlanger, KY 41018, USA
e-mail: [email protected]
in order to show how H-Factors can be incorporated into a media type in order to
produce a data format that can act as an engine of application state.
Hypermedia as Links
The idea of hypermedia was given public voice by Vennevar Bush (1945) as a way
to help researchers deal with what was perceived in the 1940s as an explosion of
information. Bush described his idea for the “Memex” in a 1945 article, “As We
May Think.” In it he states, “The human mind ... operates by association. With one
item in its grasp, it snaps instantly to the next that is suggested by the association
of thoughts, in accordance with some intricate web of trails carried by the cells of
the brain.” (Bush 1945). He wanted to make it possible for information to be shared
(using microfilm) and loaded into personal readers that could find links between
subjects and allow the user to easily jump from one document to the next, following
a single line of thought through a vast array of available content.
Decades later, in the 1974 self-published work, Computer Lib/Dream Machines
(Nelson 1974), Theodor Nelson echoed Bush claiming “...writers do better if they
don’t have to write in sequence ... and readers to better if they don’t have to
read in sequence...” In this same work, Nelson coins the terms “hypertext” and
“hypermedia” saying “By ‘hypertext,’ I mean non-sequential writing – text that
branches and allows choices to the reader, best read at an interactive screen. As
popularly conceived, this is a series of text chunks connected by links which offer
the reader different pathways.” (Nelson 1974).
In both these examples, hypermedia is thought of as a way to provide links
between related materials and enable readers to move freely along these related
paths. Hypermedia, in this case, is limited to a read-only experience meant for
enriching reading, discovery, and comprehension of text.
1
The words “hypertext”, “hyperdata” and “hypermedia” all have seen active use; sometimes to
mean different things. In this chapter, the word “hypermedia” indicates the general concept of
links that provide ‘jumps’ or branches in text or any visual display. Therefore, throughout the rest
of this chapter “hypermedia” will be used exclusively.
4 Hypermedia Types 95
While the movement to enable improving the use-ability of text was underway, a
second line of thought was also taking shape. That of using hypermedia as a way
to control the location and retrieval of data for display to the user: hypermedia as a
feature of graphical use interfaces.
As a radar station operator in the Philippines during World War II, Doug
Engelbart happened upon Vannevar Bush’s magazine article and was fascinated
with the idea of the “Memex.” Years later, Engelbart would publish “Augmenting
Human Intellect: A Conceptual Framework” (Engelbart 1962) where he laid out his
interpretation of Bush’s vision.
“Most of the structuring forms ... stem from the simple capability of being able
to establish arbitrary linkages between different substructures, and of directing the
computer subsequently to display a set of linked substructures with any relative
positioning we might designate among the different substructures.” (Engelbart
1962).
By 1968, Engelbart had developed the NLS (oN-Line System) for sharing
research information. His demonstration included not just a computer information
system capable of supporting links between items, but the first “mouse” pointing
device that could be used to actuate those links on screen. A video demonstration of
this early hypertext system is still available for viewing (Engelbart 1968).
Later, in 1987, Jeffrey Conklin published “Hypertext: An Introduction and
Survey” (Conklin 1987) which described hypertext as “...a computer-supported
medium for information in which many interlinked documents are displayed with
their links on a high-resolution computer screen.” Conklin’s work focuses on the
role hypertext plays in graphical user interfaces (GUIs) and their influence on user
interfaces in general. Conklin also compares editing environments for hypertext
content.
Additional development of the personal computer through the 1980s and early
1990s introduced more display options and additional ways to express hypermedia
links. The concept of hypermedia was expanded to include actuating interface
controls such as selectors and buttons and spawned an emphasis on visual controls
users can activate at any time. Hypermedia had become more than linking text, it
was also a visual “affordance” to animate user displays.
At the same time personal computer displays were providing more graphical
controls, early versions of the World Wide Web appeared. In 1991, Tim Berners-
Lee’s WWW was available and, by 1993 the NSCA Mosaic Web Browser had
become the popular graphical user interface for the WWW.
96 M. Amundsen
Along with the assumed graphical link elements that allowed WWW users to
“jump” from one document to the next (or within documents), Web browsers had the
ability to render images within the current document and the ability to send content
to the server using link templates implemented as forms with input elements users
could fill in and submit.
With the introduction of forms, hypermedia was no longer limited to static, read-
only experiences. Documents could be created that allowed users to send data as
well as find and retrieve it. HTML, the de facto document format for the WWW,
allowed for the inclusion of application controls along with human-readable text.
Years later, in a slide presentation to ApacheCon 2005 Roy Fielding would
describe this use of hypertext: “When I say hypertext, I mean the simultaneous
presentation of information and controls such that the information becomes the
affordance through which the user (or automaton) obtains choices and selects
actions.” (Fielding 2008).
Hypermedia as Architecture
The notion of hypermedia as more than text, more than data, but also application
controls that allow users to make choices along the way is an important requirement
for RESTful implementations over distributed networks. In addition to representing
the state of the requested resource, Hypermedia documents contain the affordances
for changing the state of the application. It is the hypermedia that makes state
transitions possible. This alters the role of server responses from simple data replies
to that of an essential part of the network architecture.
The idea that data itself (whether simple state information or hypermedia
controls) can be part of the network architecture was articulated by Fielding (2000)
as “...the nature, location, and movement of data elements within the system is
often the single most significant determinant of system behavior.” Even more
directly, Fielding continues “The nature of the data elements within a network-based
application architecture will often determine whether or not a given architectural
style is appropriate.” Finally, Fielding identifies hypermedia specifically as the
“engine of application state.”
Summary
This section focused on various views of hypermedia itself; from read-only links
to application controls. This last aspect of hypermedia – as a way to control
applications through state transitions – has an important relation to architectural
styles for distributed networks themselves. When responses are expressed as
hypermedia documents, these responses are more than just data, they are also part
of the network architecture.
Finally, a formal definition of the term “Hypermedia Type” was introduced.
This section identifies nine factors native within a media type that can be used
to support hypermedia behaviors. These nine “H-Factors” can be expressed in
various ways, depending on the media type itself. However, no matter what actual
98 M. Amundsen
elements or attributes are used to express these factors, the factors themselves
remain essentially the same across all hypermedia types.
Hypermedia Factors
CL
this figure will be
printed in b/w
CR CU CM
LE LO LT LN LI
Hypermedia factors
Links LO Outbound Links
LE Embed Links
LT Templates Links
LN Non-Idempotent Links
LI Idempotent Links
Control data CR Read Controls
CU Update Controls
CM Method Controls
CL Link Annotation Controls
Embedded Links: LE
The LE factor indicates to the client application that the accompanying URI should
be de-referenced using the application-level protocol’s read operation (e.g. HTTP
GET) and the resulting response should be displayed within the current output
4 Hypermedia Types 99
window. In effect, this results in merging the current content display with that
of the content at the “other end” of the resolved URI. This is sometimes called
“transclusion.”
A typical implementation of the LE factor is the IMG markup tag in HTML:
<img src="..." />
In the above example, the URI in the src attribute is used as the read target and
the resulting response is rendered “inline” on the Web page.
In XML, the same LE factor can be expressed using the x:include element.
<x:include href="..." />
Outbound Links: LO
The LO factor indicates to the client application that the accompanying URI
should be de-referenced using the application-level protocol’s read operation and
the resulting response should be treated as a complete display. Depending on
additional control information, this may result in replacing the current display with
the response or it may result in displaying an entirely new viewport/window for the
response. This is also known as a “traversal” or “navigational” link.
An example of the LO factor in HTML is the A markup tag:
<a href="...">...</a>
In a common Web browser, activating this control would result in replacing the
current contents of the viewport with the response. If the intent is to indicate to the
client application to create a new viewport/window in which to render the response,
the following HTML markup (or a similar variation) can be used:
<a href="..." target="_blank">...</a>
Templated Links: LT
The LT factor offers a way to indicate one or more parameters that can be supplied
when executing a read operation. Like the LE and LO factors, LT factors are read-
only. However, LT factors offer additional information in the message to instruct
clients on accepting additional inputs and including those inputs as part of the
request.
The LT element is, in effect, a link template. Below is an example LT factor
expressed in HTML using the FORM markup tag:
<form method="get" action="http://www.example.org/">
<input type="text" name="search" value="" />
<input type="submit" />
</form>
100 M. Amundsen
HTML clients understand that this LT requires the client to perform URI
construction based on the provided inputs. In the example above, if the user typed
“hypermedia” into the first input element, the resulting constructed URI would
look like this:
http://www.example.org/?search=hypermedia
The details on how link templates (LT) are expressed and the rules for construct-
ing URIs depends on the documentation provided within the media type itself.
Templated links can also be expressed directly using tokens within the link itself.
Below is an example of a templated link using specifications from the URI Template
I-D (Gregorio et al. 2010):
<link href="http://www.example.org/?search={search}"/>
Non-Idempotent Links: LN
The LN factor offers a way to send data to the server using a non-idempotent
“submit.” This type of request is implemented in the HTTP protocol using the POST
method. Like the LT factor, LN can offer the client a template that contains one or
more elements that act as a hint for clients. These data elements can be used to
construct a message body using rules defined within the media type documentation.
The HTML FORM element is an example of a non-idempotent (LN) factor:
<form method="post" action="http://example.org
/comments/">
<textarea name="comment"></textarea>
<input type="submit" />
</form>
In the above example, clients that understand and support the HTML media type
can construct the following request and submit it to the server:
POST /comments/ HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
Length: XX
comment=this+is+my+comment
It should be noted that the details of how clients compose valid payloads can
vary between media types. The important point is that the media type identifies and
defines support for non-idempotent writes.
4 Hypermedia Types 101
Idempotent Links: LI
The LI factor provides a way for media types to define support for idempotent
submits. These types of requests in the HTTP protocol are supported using the PUT
and DELETE methods. While HTML does not have direct support for idempotent
submits within markup (e.g. FORM method="PUT"), it is possible to execute
idempotent submits within an HTML client using downloaded code-on-demand.
Below is an example idempotent link factor (LI) expressed using Javascript:
<script type="text/javascript">
function delete(id)
{
var client = new XMLHttpRequest();
client.open("DELETE", "http://example.org
/comments/"+id);
}
</script>
The Atom media type implements the LI factor using a link element with a
relation attribute set to “edit” (rel="edit"):
<link rel="edit" href="http://example.org/edit/1"/>
Clients that understand the Atom specifications know that any link decorated in
this way can be used sending idempotent requests (HTTP PUT, HTTP DELETE)
to the server.
Read Controls: CR
One way in which media types can expose control information to clients is to sup-
port manipulation of control data for read operations. The HTTP protocol (Fielding
et al. 1999) identifies a number of HTTP Headers for controlling read operations.
One example is the Accept-Language header. Below is an example of XInclude
(Marsh et al. 2006) markup that contains a custom accept-language attribute:
<x:include
href="http://www.exmaple.org/newsfeed"
accept-language="da, en-gb;q=0.8, en;q=0.7"
/>
Update Controls: CU
Support for control data during send/update operations (CR) is also possible. For
example, in HTML, the FORM can be decorated with the enctype attribute.
102 M. Amundsen
The value for this attribute is used to populate the Content-Type header when
sending the request to the server.
<form method="post"
action="http://example.org/comments/"
enctype="text/plain">
<textarea name="comment"></textarea>
<input type="submit" />
</form>
In the above example, clients that understand and support the HTML media type
can construct the following request and submit it to the server:
POST /comments/ HTTP/1.1
Host: example.org
Content-Type: text/plain
Length: XX
this+is+my+comment
Method Controls: CM
Media types may also support the ability to change the control data for the protocol
method used for the request. HTML exposes this CM factor with the method
attribute of the FORM element.
In the first example below, the markup indicates a send operation (using the
POST method). The second example uses the same markup with the exception that
the GET method is indicated. This second example results in a read operation.
<form method="post" action="..." />
<input name="keywords" type="text" value="" />
<input type="submit" />
</form>
Link Controls: CL
In addition to the ability to directly modify control data for read and submit
operations, media types can define CL factors which provide inline metadata for
4 Hypermedia Types 103
the links themselves. Link control data allows client applications to locate and
understand the meaning of selected link elements with the document. These CL
factors provide a way for servers to “decorate” links with additional metadata using
an agreed-upon set of keywords.
For example, Atom (Nottingham et al. 2005) documentation identifies a list of
registered Link Relation Values (IANA Protocol Registries 2011) that clients may
encounter within responses. Clients can use these link relation values as explanatory
remarks on the meaning and possible uses of the provided link. In the example
below, the Atom entry element has a link child element with a link relation
attribute set to “edit” (rel="edit").
<entry xmlns="http://www.w3.org/2005/Atom">
<title>Atom-Powered Robots Run Amok</title>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-
80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<author><name>John Doe</name></author>
<content>Some text.</content>
<link rel="edit" href="http://example.org/edit/1"/>
</entry>
Clients that understand the Atom and AtomPub (Gregorio et al. 2007) specifica-
tions know (based on the documentation) that any link decorated in this way is the
link to use when sending idempotent submits (HTTP PUT, HTTP DELETE) to
the server.
Another example of using CL factors is HTML’s use of the rel=
"stylesheet" directive (see below).
<link rel="stylesheet" href="..." />
In the above example, the client application (Web browser) will use the URI
supplied in the href attribute as the source of style rendering directives for the
markup in the HTML document.
Summary
This section identified nine Hypermedia Factors; one or more of which can be
found in a media type document. The presence of these factors within the media
type definition mark it as a hypermedia type and indicate support for various
protocol-level hypermedia semantics. MIME media types that contain one or
more of these factors promote RESTful implementations by making it possible to
include application controls within the requests and responses. These hypermedia
application controls are the elements of the message advance application flow.
104 M. Amundsen
Some well-known media types are not covered here including XML (Bray et al.
2008) and JSON (Crockford 2006). These two (and similar ones) have been left out
for an important reason: they contain no native H-Factors as part of their definition.
In other words, these media types exhibit no defined elements capable of expressing
any of the previously identified H-Factor links (LO, LE, LT, LI, LN) or control data
(CR, CU, CM, CL).3
2
It should be noted that these are not the only media types that warrant hypermedia analysis. They
are also not selected here as excellent examples of Hypermedia Types, but merely as familiar media
types worthy of review.
3
While it is true that media types such as XML and JSON allow designers to define link and
control elements using the basic elements of that media type, this does not qualify as providing
native support for H-Factors.
4 Hypermedia Types 105
URI List
http://www.huh.org/books/foo.pdf
ftp://ftp.foo.org/books/foo.txt
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI
URI List
This media type is designed to convey a list of one or more URIs that can be
resolved and/or processed by the recipient. For the sake of analysis, this media
type provides support for the LO (Outbound Link) Hypermedia Factor. It might be
argued that the URIs could be treated by recipients as LE (Embedded Links) (e.g.
image links merged into an existing document), but most of the suggested uses in
documentation point to de-referencing and processing each URI in turn rather than
using the list to produce a single composite document.
SVG
Similar to the text/uri-list media type, the SVG media type (Dahlstrm
this figure will be printed in b/w
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI
SVG
106 M. Amundsen
Atom
The Atom media type profile is defined by two specifications Atom (Nottingham
et al. 2005) and AtomPub (Gregorio et al. 2007). There are three registered me-
dia types associated withAtom: application/atom+xml, application/
atomcat+xml, and application/atomsvc+xml. The Atom specification
outlines the message format and elements for the application/atom+xml
this figure will be printed in b/w
media type. The AtomPub specification covers the details for the remaining two
media types as well as the read/write semantics for all three media types.
Hypermedia Factors
CL
CR CU CM
LE LO LT LN LI
Atom
The primary hypermedia element in the Atom media type family is the
atom:link element:
The link element show above supports LO, CR, and CL H-Factors. The Atom
semantic model also supports LI and LN H-Factors by identifying markup elements
within the response that have special significance.
For example, non-idempotent writes can be used to add new entry elements to
the collection. Clients are instructed to locate the atom:link element associated
with the root of the response which is marked with rel="self". This element’s
href is the “Collection URI” and is the target URI for executing non-idempotent
writes to the collection:
<feed xmlns="http://www.w3.org/2005/Atom">
<link href="..." rel="self" />
...
</feed>
Idempotent writes (including updates and deletions) are indicated using the
rel="edit" attribute on a link element that is the child of an entry element
(see example below).
<entry>
<link href="..." rel="edit" />
...
</entry>
There are a handful of other elements in the Atom media type family that support
both LO and LE H-Factors including:
atom:collection (LO)
atom:content (LO,LE)
atom:generator (LO)
atom:icon (LE)
atom:logo (LE)
atom:uri (LO)
It should be noted that the Atom media type family uses documentation
convention to communicate the details of a valid write payload (LI, LN) and does
not include these details within the response message itself. Also, Atom has no
native support for Templated Links (LT).
HTML
The HTML (Raggett et al. 1999) media type offers a wide range of support for
H-Factors including: LO, LE, LT, LN and CU, CM, CL. The only H-Factors not
supported in the HTML media type are LI (idempotent writes) and CR (control data
for reads).
108 M. Amundsen
Hypermedia Factors
CL
this figure will be
CR CU CM
printed in b/w
LE LO LT LN LI
HTML
Simple outbound and embedded links are handled, for example, using the A and
IMG tags respectively:
<a href="...">...</a>
<img src="..." />
HTML is the only media type covered in this chapter that supports Templated
Links (LT). Templated links are similar to the LO H-Factor except that LT elements
allow for URI variables to be defined by the sender and the values for these variables
to be supplied by the client. In the HTML media type, this is accomplished using
the FORM element with the method="get" attribute. The URI for the operation
is found in the action="..." attribute. Below is an example:
In the above case, HTML documentation instructs clients to use the inputs to
construct a message body using (the default) application/x-www-form-
urlencoded media type format. The resulting HTTP request sent to the server is:
POST /products HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
Length: XX
color=red&size=large
It should be noted that, unlike the Atom media type which relies on documen-
tation to tell clients how to compose a valid write message, the HTML media type
allows servers to send clients write templates within the response and to use that
template to compose a valid write request.
As seen in the two previous examples (LT and LN), HTML supports customizing
control data protocol methods used for requests (CM) through the use of the
method attribute of the FORM element and support for customizing control data
for updates (CU) using the enctype attribute of the same element.
HTML also supports customizing control data for links (CL) using the rel
attribute for the link tag. In the following example, the HTML client will use
the response for the URI as style rules for adjusting the rendering of the content.
<link rel="stylesheet" href="... type="text/css" />
Summary
This section reviewed a representative sample of registered MIME media types and
subjected them to a simple analysis in order to identify native elements within the
media type that express one or more of the identified H-Factors. The analysis was
cursory (in order to save time and space), but the reader should now have a good
idea of how this can be undertaken for any registered (or proposed) media type
design.
Armed with the knowledge of the nine Hypermedia Factors and experience analyz-
ing existing media types, it is possible to construct a prototypical media type that
illustrates each of the H-Factors defined in this chapter.
The goal of this exercise is to create an “illustration” media type that can be
used as a guide when setting out to analyze other media types or as an aide
110 M. Amundsen
for those wishing to design their own Hypermedia Type. This prototypical media
type contains all the identified H-Factors (LO, LE, LT, LN, LI and CR, CU,
CM, CL).
What follows are the specifications for a media type called Prototypical Hyper-
media Application Controls for Text-Oriented Representations or PHACTOR4 . Like
HTML, PHACTOR is a hypermedia type designed to support rendering and layout
of text-based documents. For this reason, the reader will find many similarities
between HTML and PHACTOR.
PHACTOR is an XML-based media type used for representing simple text and a
basic set of application controls. The main layout of a valid PHACTOR document is:
<document>
<meta />
<content />
</document>
The meta section can optionally hold one each of the following: title,
updated, author.
<document>
<meta>
<title>H-Factor Sample</title>
<updated>2010-06-15</updated>
<author>MikeA</author>
</meta>
<content />
</document>
The content section can optionally hold one or more of the following
elements (shown here in parent-child order): section, para, text. The
title element may also appear as the first child of a section element. Also, the
eol (‘end-of-line’) element can be used to create line breaks within a block of text.
<document>
<meta>
<title>H-Factor Sample</title>
<updated>2010-06-15</updated>
<author>MikeA</author>
</meta>
4
At the time of this writing, the PHACTOR media type has been submitted to the IANA Media
Type registry with the application/vnd.phactor+xml MIME type identifier.
4 Hypermedia Types 111
<content>
<section>
<title>An implementation</title>
<para>
<text>
This is a trivial hypermedia type
implementation.<eol/>
This is a new line in the document.
</text>
</para>
</section>
</content>
</document>
In addition to simple text and layout elements, the PHACTOR media type supports
the following link elements: LO, LE, LT, LN, LI. These link elements can
appear as child elements of the following elements: content, section,
para. Also, the LT, LN, LI elements may have one or more optional data
child elements. The data can be used to create link templates (LT) and to populate
LN and LI representations to send to the server.
Below are examples of each of the link elements. Note that both the LT and LN
elements use data child elements to define templates.
<LO href="http://example.org" label="example.org" />
<LE href="http://example.org/images/photo.jpg"
label="Photo" />
The PHACTOR media type supports optional control data for linking elements
CR, CU, CM, CL. The LE element supports the CR="[acceptLanguage]"
attribute to allow customizing the Accept-Language header of the
request. The LI element supports the CM="[protocolMethod]" and
CU="[contentType"] attributes to allow customizing the request with the
protocol method and content type string respectively.
All five link types (LO, LE, LT, LI, LN) support the use of the CL =
"[linkRelationValue]" attribute in order to decorate hypermedia links with
additional metadata. Valid values for this attribute can be any registered link relation
value or any fully-qualified unique URI [per RFC5988 (Nottingham 2010)]. It is up
to the client application to determine the importance and meaning of this value.
Since the PHACTOR media type is based on XML, it is relatively easy to load,
parse, and render using modern Web browsers. All modern Web browsers support
client-side XSLT transformations. For the PHACTOR media type, each response can
be accompanied by an XSLT stylesheet directive like the one below:
<?xml-stylesheet type="text/xsl" href="phactor.xsl"?>
114 M. Amundsen
This directive can be used by the browser client to transform the XML response
into valid XHTML that can be rendered by the client application. Also, since
PHACTOR has support for Idempotent Links (LI), a full-featured Web browser
implementation requires use of the XMLHttpRequest API (van Kesteren 2010).
Below is a partial listing of the transformation document:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"
media-type="text/html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="DTD/xhtml1-strict.dtd"
cdata-section-elements="script style"
indent="yes"
encoding="ISO-8859-1"/>
<xsl:template match="/">
<html>
<head>
<xsl:apply-templates select="//meta" mode=
"head" />
<link href="doc.css" rel="stylesheet" type="
text/css" />
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
</xsl:template>
...
4 Hypermedia Types 115
Summary
In this chapter the varying role of hypermedia was reviewed including usage to
express read-only links, act as GUI controls, and as a way to provide support for
state transitions between distributed components. Hypermedia was also viewed from
the perspective of network architecture itself.
Special attention was given to MIME Media Types and their use in HTTP in
order to carry hypermedia information. It was observed that only a subset of MIME
media types exhibit native hypermedia elements and these media types were used
as the basis for a formal definition of “Hypermedia Type.”
Nine native Hypermedia Factors (H-Factors) were introduced to show how
media types can express application controls for various state transition activities
in a RESTful implementation. In addition, several well-known registered media
types were analyzed for the presence of H-Factors in order to quantify support for
hypermedia in each media type.
Finally, a prototypical hypermedia type (PHACTOR) was presented to illustrate
how media types can be designed using H-Factors. A sample page was presented and
a sample PHACTOR user agent implementation based on a modern Web browser’s
support for XSLT and XMLHttpRequest was discussed.
References
Bray, Tim, Ed. et al., Extensible Markup Language (XML) 1.0 (Fifth Edition), http://www.w3.org/
TR/xml/ (2008)
Bush, Vannevar, As We May Think, Atlanic Magazine, July 1945
Conklin, Jeff, Hypertext: An Introduction and Survey in IEEE Computer, 20(9), 17–41, September
1987
Crockford, Douglas, The application/json Media Type for JavaScript Object Notation (JSON),
http://tools.ietf.org/html/rfc4627 (2006)
Dahlstrm, Erik, et al., Scalable Vector Graphics (SVG) 1.1 (Second Edition), http://www.w3.org/
TR/SVG/ (2011)
Engelbart, Douglas, Augmenting Human Intellect: A Conceptual Framework, October 1962
Engelbart, Douglas, The Demo, http://sloan.stanford.edu/mousesite/1968Demo.html (1968)
Fielding, Roy Thomas, Architectural Styles and the Design of Network-based Software Architec-
tures. Doctoral dissertation, University of California, Irvine, 2000
Fielding, Roy Thomas, REST APIs must be Hypertext-driven, http://roy.gbiv.com/untangled/2008/
rest-apis-must-be-hypertext-drivencomment-718 (2008)
Fielding, Roy Thomas, Ed. et al., Hypertext Transfer Protocol – HTTP/1.1, http://tools.ietf.org/
html/rfc2616 (1999)
Gregorio, J., Ed. et al., URI Template, http://tools.ietf.org/html/draft-gregorio-uritemplate-04
(2010)
Gregorio, J., Ed. et al., The Atom Publishing Protocol, http://tools.ietf.org/html/rfc5023 (2007)
IANA Protocol Registries, Link Relations, http://www.iana.org/assignments/link-relations/ (2011)
van Kesteren, Anne, XMLHttpRequest, http://www.w3.org/TR/XMLHttpRequest/ (2010)
Marsh, Jonathan, et al., XML Inclusions (XInclude) Version 1.0 (Second Edition), http://www.w3.
org/TR/xinclude/ (2006)
116 M. Amundsen
Mealling, M. et al., URI Resolution Services Necessary for URN Resolution, http://tools.ietf.org/
html/rfc2483 (1999)
Nelson, Theodor H., Literary Machines. Swarthmore, Pa.: Self-published (1974)
Nottingham, M., Web Linking, http://tools.ietf.org/html/rfc5988 (2010)
Nottingham, M., Ed. et al., The Atom Syndication Format, http://tools.ietf.org/html/rfc4287 (2005)
Raggett, Dave, Ed. et al., HTML 4.01 Specification, http://www.w3.org/TR/html401/ (1999)
Chapter 5
Beyond CRUD
Abstract REST web services offer interfaces to create, retrieve, update and delete
information from a database (also called CRUD interfaces). However, REST web
services can also be used to create rich services that offer more than simple CRUD
operations and still follow the REST architectural style. In such a case it is important
to create and publish behavioral service interfaces that developers can understand in
order to use the service correctly. In this chapter we explain how to use models to
design rich REST services. We use UML class diagrams and protocol state machines
to model the structural and behavioral features of rich services. The design models
are then implemented in Django Web Framework. We also show how to use the
behavioral interfaces to implement a service monitor.
Introduction
The interface of a web service advertises the operations that can be invoked on it.
A web service developer looking for a particular service finds the service over the
web and integrates it with other services by invoking the advertised operations and
providing it the required parameters.
Many RESTful web services present simple interfaces to create, retrieve, update
and delete information from a database (also called CRUD interfaces). However,
REST is not limited to simple CRUD applications. It is possible to create web
services exhibiting a rich application state that still follow the REST architectural
style, e.g., flight and hotel reservation systems, stock trading services etc. In such
cases, it is important to create and publish behavioral service interfaces so other
developers can understand how to use a service correctly. A behavioral interface
I. Rauf ()
Department of Information Technologies ICT, Abo Akademi University,
Joukahainengatan 3-5 A, FI-20520 ABO, Finland
e-mail: [email protected]
of a web service provides information about the order of invocation and about any
special conditions under which interface methods can be invoked and their expected
effect.
A REST interface should offer features of addressability, connectedness, uniform
interface and statelessness. In order to provide these interface features for beyond
CRUD REST applications along with behavioral interface specifications, we present
a design methodology that caters to the REST design philosophy earlier in the devel-
opment cycle (Porres and Rauf 2011). The design approach addresses modeling of
REST features using UML (Unified Modeling Language) (OMG UML 2009), thus
creating web services that are RESTful by construction. In this chapter, we overview
the design methodology presented in Porres and Rauf (2011) and then detail how the
design approach is implemented in Django Web Framework. The service monitor
implemented in Django Web Framework checks the correctness of a service with
regard to its design.
In the next two sections, we show how these models are developed. We use
as example an imaginary hotel room booking (HRB) service. The service allows
a client to book a room, pay for the reservation, and cancel it. It is a simplified
pedagogical example, but it shows how to design a REST interface for a service
with a complex application state.
Figure 5.1 shows representation of resources in the HRB service. For example,
room resource contains three attributes i.e. rid, rType and floor. Room ID(rid) and
floor(floor) are integer values and room type(rType) is a string value. Attributes are
modeled as a public attribute as the representation of a resource is available for
manipulation.
Classes are connected via associations and each association is marked with role
names on association ends. These associations show connection between resources
and their multiplicity shows number of resources that can be related to the resource
on the other end of the resource. These associations provide addressability and
connectivity features to web service interface as explained in the next section.
/bookings/{bid}/
/bookings/{bid}/cancel/
/bookings/{bid}/payment/
/bookings/{bid}/rooms/{rid}/
/bookings/{bid}/payment/pconfirmation/
/bookings/{bid}/payment/pwaiting/
/rooms/{rid}/
/rooms/{rid}/booking/
/rooms/{rid}/booking/cancel/
/rooms/{rid}/booking/payment/
/rooms/{rid}/payment/pconfirmation/
/rooms/{rid}/payment/pwaiting/
The REST style requires that all resources should be addressable and connected.
Thus, we require that our resource model should not contain an isolated resource.
Each resource can be reached from at least one collection resource by navigating
one or more associations.
Uniform Interface
A UML class diagram allows us to define a number of operations for each class.
Since a RESTful web service provides uniform interface for all resources, all
resources would only have from one to four method names GET, POST, PUT, and
DELETE. Thus, we do not show operation information in the conceptual resource
model. However, by constraining the allowed transition triggers in behavioral model
to the standard HTTP method we comply with the uniform interface requirement.
The purpose of the behavioral model is to describe the behavioral interface speci-
fications of a RESTful web service. It shows the sequence under which operations
should be invoked, the conditions under which they can be invoked and the expected
results.
We use a UML protocol state machine with state invariants to describe the
allowed operations in a web service. A UML protocol state machine is suitable
for representing the behavior of a web service as it provides interface specifications
that give information about conditions under which methods can be invoked and
their expected output.
A UML protocol state machine contains mainly states and transitions. We require
that each state has a state invariant that is defined as a boolean expression. We then
say that a state is active if and only if its state invariant evaluates to true. A state
may contain other states and is called a composite state. In such a case, the actual
122 I. Rauf and I. Porres
state invariant of the contained state is given by the conjunction of the state invariant
specific for the contained state and the state invariants of all the states that contain it.
These state invariants within a composite state should be mutually exclusive. That
is, only one state within a region of a composite state can be active at a time.
A transition is an arc from one or more source state(s) to one or more target
state(s) labeled with a method name and a guard. If the source states are active,
the guard is true and the method is invoked, then the transition may be fired and
as a consequence the target state(s) become active. When no guard is shown in the
transition it is assumed to be true.
Since we are describing RESTful web interfaces, the only allowed operations are
GET, POST, PUT, and DELETE on resources.
The GET method retrieves representation of a resource and it should not have
side effects, i.e., not cause a change in the state of the system. Due to the addressabil-
ity requirement, it is possible to always invoke a GET method over a resource. For
example, GET(/bookings/fbookingIdg/payment/) and GET(/bookings/fbookingIdg/
cancel/) represent GET requests on resources payment and cancel, respectively.
Whenever a GET method is invoked on a resource, it gives the representation of
resource as a response if the resource is present, else a response code of 404 is sent
back. In practice, the access to resources may be restricted by an authentication and
access control mechanism.
The transition triggers can only be defined as POST, PUT, or DELETE operations
over resources described in the conceptual model. The POST, PUT, and DELETE
methods can have side effects, i.e., they can cause a change in the state of the system.
Our behavioral model shows different states of a RESTful web service and gives
information on what HTTP methods on a particular resource can be invoked from
a certain state. According to Fig. 5.2, the protocol state machine of HRB service
is initiated by the HTTP POST method on the bookings resource. The client can
make payment for a booking by invoking a PUT method on payment resource only
if the name of the credit card is same as the name of the guest. The booking service
invokes a third party credit card payment service(CCService) from the paid state
as an internal action. If the CCService is asynchronous, then the booking service
invokes a PUT on pwaiting resource and the transaction enters a wait state. It
then invokes a PUT on pconfirmation resource when response is received from
the CCService. If the CCService is synchronous, the booking service invokes a
PUT on pconfirmation resource from the paid state when it receives response from
the CCService. The case of synchronous and asynchronous services is explained in
“Synchronous and Asynchronous Web Services.” A booking can be canceled from
the composite state reserve and pay and simple state pconfirmation info. A booking
cannot be canceled if it is waiting for the payment confirmation from a third-party
service. A booking can be deleted only if it is canceled. Note that all the information
needed to process the request on a resource are contained in the invoked method
and URL.
A GET method can be invoked on every resource as it is free of any side-effect.
However, a closer look at the behavioral model also exposes information about
the allowed side-effect methods on a resource. For example, Fig. 5.2 shows that
5 Beyond CRUD 123
State invariants show the current state of an application during the lifecycle of
an object. We are representing behavioral interface of a REST web service using
protocol state machines. REST invocations do not contain any state or session
information, so defining state invariants for REST application states is not obvious.
124 I. Rauf and I. Porres
Fig. 5.3 (Left) Interaction with Synchronous CC Service. (Right) Interaction with Asynchronous
CC Service
For synchronous service, there is no need for a waiting state since the service
does not take long to respond and system can continue with its processing after
receiving the response. This is shown in Fig. 5.2 by a direct transition from paid
state to pconfirmation info state with PUT(pconfirmation) as a trigger.
The two scenarios showing the request and response behavior in synchronous
and asynchronous services is shown in Fig. 5.3. The left side shows the scenario
in which credit card(CC) verification service is synchronous and on the right hand
side show interaction with an asynchronous CC verification service. It may be worth
pointing out that the agent PUTing the payment (the client) must also be able to act
as a server in order to receive a PUT payment confirmation. As an alternative, the
CCService might return 202(Accepted) response with location. This would require
the client to poll for confirmation.
We have used state machines to model the stateless behavior of REST web service.
Using a state machine to model a stateless interface may seem an oxymoron. In the
context of a RESTful service, statelessness is interpreted as the absence of hidden
information kept by the service between different service requests. In that sense, a
RESTful web service should exhibit a stateless protocol. Also, there is no sense of
session or sequence of request in a true RESTful service.
On the other hand, state machines have a notion of active state configuration,
that is, what states are active at a certain point of time. If an implementation of
an interface described using a state machine would have to keep the active state
configuration between different requests, then this would break the statelessness
requirement of the RESTful service.
It is notable that the behavioral modeling described above, does not actually
require that a service implementation keeps any additional protocol state. In our
126 I. Rauf and I. Porres
approach a state is active if its invariant evaluates to true, but the invariants are
defined using addressable application resources. Therefore, an implementation of
a service can determine the active state configuration by querying the application
state. There is no need to keep any additional protocol state.
Determining what is the active state configuration of the interface state machine
every time that a service implementation has to fulfill a request may be a slow task
in the case of complex interfaces with many states. However, in practice it is not
necessary to explore all states in the state machine but only the source states of the
transitions that can be triggered based on the current request. We show in the next
section how we can do that by computing the precondition (and postcondition) of
each method request.
In this section, we show how to extract the contract information from a UML
protocol state machine with state invariants. The contract contains the precondition
and postcondition for each method that triggers a transition in the behavioral model.
The precondition of a method states under what conditions a method can be
triggered. We say that the precondition of a method m is satisfied when the state
invariants of all the source states of transition t are true along with its guard
condition.
In a similar manner, if a method m triggers a transition t in a behavioral model,
then its post-condition is satisfied when the state invariants of all the target states of
transition t are true along with the postcondition annotated on the transition t.
In order to shorten the description of the contract we use path variables to
represent the address of a resource. First, the precondition for a method that triggers
a transition in the behavioral model is presented. The precondition of a method m is
given by taking into account all the transitions that are triggered by m. If it is a simple
transition, then the state invariant of its source state is conjuncted with the guard of
the transition. In case the transition is a trigger to more than one transition, with true
guards, and all the transitions have different source states, then the precondition is
given by taking a disjunction of state invariants of all the different source states. This
implies that the method can trigger a transition whenever it is in one of its source
states.
A transition can occur from one state to another if the method that triggers this
transition is invoked and its precondition is true. For the transition to be successful,
the postcondition of the transition should also be true after the method is invoked.
This is specified by the implication operator that relates a precondition of a transition
with its postcondition.
A postcondition for a method is extracted from the protocol state machine
by manipulating the state invariants of the target states of transitions and the
post-conditions on transitions. The post-condition of a fork transition, with true
5 Beyond CRUD 127
postcondition, specifies that the state invariants of all its target states are true and
for a self-transition, its post-condition ensures that the same state invariants are true
that were true before invoking the HTTP method.
For the details and formal definitions of generating preconditions and postcondi-
tions for different elements in a UML protocol state machine of a class readers are
referred to Porres and Rauf (2010).
The postcondition of a transition will be evaluated only if the precondition for
that transition is true. We define as pre OK(r) the function that gives boolean
value of OK(r) on resource r before invoking the trigger method. Similarly,
pre b.guestName and pre NOT FOUND(r) give the representation of booking and
boolean value of NOT FOUND(r) before invoking the trigger method, respectively.
The excerpt below from the list of high-level contracts generated from Fig. 5.2
shows the contracts generated for the HTTP method PUT on payment resource.
PATH
b: bookings/{bid}/
r: bookings/{bid}/rooms/
p: bookings/{bid}/payment/
pc: bookings/{bid}/payment/pconfirmation/
pw: bookings/{bid}/payment/pwaiting/
c: bookings/{bid}/cancel/
PUT {bookings/{bid}/payment/}
precondition
((OK(b) && OK(r) && NOT_FOUND(c)) &&
(NOT_FOUND(pc) && NOT_FOUND(pw)) && NOT_FOUND(p) &&
[b.guestName == ccName])
postcondition
((pre_OK(b) && pre_OK(r) && pre_NOT_FOUND(c)) &&
(pre_NOT_FOUND(pc) && pre_NOT_FOUND(pw)) && pre_NOT_FOUND
(p) && [pre_b.guestName == ccName]) ==> ((OK(b) && OK
(r) && NOT_FOUND(c)) &&
(NOT_FOUND(pc) && NOT_FOUND (pw))&& OK(p))
The conceptual model as shown in Fig. 5.1 and behavioral model as show in
Fig. 5.2 are implemented as REST web services. This is explained further in the
next section.
Django is a web framework that makes it easy to develop web applications and
web services in Python. At a glance, Django can be understood with its three
basic files that support separation of concerns, i.e. models.py, urls.py and views.py
where models.py contains descriptions of database tables, views.py contains the
business logic, and urls.py specifies which URIs map to which view. For a
128 I. Rauf and I. Porres
class room(models.Model):
rType = models.CharField(max_length=200)
floor = models.IntegerField()
class guest(models.Model):
fName = models.CharField(max_length=200)
phone = models.IntegerField()
email = models.CharField(max_length=200)
class booking(models.Model):
bDate = models.DateTimeField()
cancel = models.BooleanField(default=False)
cancel_note = models.CharField(max_length=500)
room = models.ForeignKey(room)
gName = models.CharField(max_length=500)
class payment(models.Model):
amount = models.FloatField()
pDate = models.DateTimeField()
confirm = models.BooleanField(default=False)
waiting = models.BooleanField(default=False)
p_try = models.IntegerField(default = 0)
ccName = models.CharField(max_length=500)
booking = models.ForeignKey(booking)
The first view booking payment.request; bid/ in Listing 5.2 shows implementa-
tion of payment resource. The behavioral model in Fig. 5.2 shows that the allowed
methods for this resource are GET and PUT. These two methods are listed in the
130 I. Rauf and I. Porres
urlpatterns = patterns(’’,
(r’ˆbookings/$’, collection_bookings),
(r’ˆbookings/(\d{1,3})/$’,
booking_detail),
(r’ˆrooms/$’, collection_rooms) ,
(r’ˆbookings/(\d{1,3})/rooms/$’,
room_detail),
(r’ˆbookings/(\d{1,3})/payment/$’,
booking_payment),
(r’ˆbookings/(\d{1,3})/payment/waiting
/$’, booking_waiting),
(r’ˆbookings/(\d{1,3})/payment/
pconfirmation/$’,
booking_pconfirmation),
(r’ˆbookings/(\d{1,3})/cancel/$’,
booking_cancel),
)
Listing 5.3 Relative URIs and views mapping for HRB Service
list of allowed methods in booking payment view and each incoming request to this
view is first verified to be one of these methods, otherwise an HTTP response of
method not allowed is given.
In the third step, the relative URIs shown in the conceptual resource model
are mapped to the respective views. Every resource in our conceptual model is
addressable. We can get the relative URI for each resource directly from Fig. 5.1
that is then mapped to the respective views as show in Listing 5.3.
Users can use cURL to invoke URIs specifying the methods they want to invoke
on the service. cURL is a command line tool that is a capable HTTP client and
5 Beyond CRUD 131
def booking_payment_get_local(bid):
p = payment.objects.filter(booking=bid)
if p:
data = serializers.serialize("json", p)
return data
else:
return None
Listing 5.4 Excerpt of Local GET View on ‘payment’ for HRB Service
implemented for each resource. The local GET views retrieve information from the
database and return them as normal objects rather than as HTTP response objects.
An implementation of local GET view on payment resource is shown in Listing 5.4.
The pre and post conditions are asserted in each of the views that correspond
to the methods that trigger a transition in state machine. Listing 5.2 shows how
pre and post conditions are asserted for PUT method on payment. Information of
the resources that form the state invariant of source states and guard condition is
stored in different variables. These variables are combined as a boolean expression
and asserted as an if condition before performing the desired task. Similarly, before
giving a success response to the client, a local get is performed on the resources that
make the state invariant of target states and transition’s post conditions. Only if the
expected behavior is observed, a success response is given to the client.
In this section, we show how we have implemented a proxy interface for HRB
service detailed above. In proxy interface, a method is implemented for each of the
methods that are invoked on the REST web service interface using urllib2. urllib2 is
a Python module that is used to fetch URLs (urllib2 extensible library for opening
URLs 2010). In a proxy interface for HRB service, a GET method on payment
resource is implemented as shown in Listing 5.5.
Each GET view returns an HTTP response object. When a POST, PUT or
DELETE method is implemented in the proxy interface, it manipulates the status
codes of the HTTP response objects and asserts them as method pre and post
conditions. An excerpt of HRB proxy interface that shows a PUT method on the
payment resource is given as shown in Listing 5.6.
Conclusions
RESTful web services can be used in rich services that go beyond simple operations
of creating, retrieving, updating, and deleting data from the database. These rich
services should also offer interface that would exhibit REST features of uniform
interface, addressability, connectedness, and statelessness. In this chapter, we
discuss the design methodology that creates RESTful web services by construction.
The approach uses UML class diagram and state machine diagram to represent the
structural and behavioral features of a REST web service. The conceptual resource
model that represents the structural feature adds addressability and connectivity
features to the designed interface. The uniform interface feature is offered by
constraining the invocation methods in the state machine to HTTP methods. In
addition, to provide the feature of statelessness in our interface we use a state
machine for behavioral modeling. This oxymoron is addressed by taking advantage
of the fact that state invariants can be defined using query method on resources and
the information contained in their response codes.
The rich behavioral specifications present in the behavioral model show the
order of method invocations and the conditions under which these methods can
be invoked along with the expected conditions. We use this behavioral model to
generate contracts in the form of preconditions and postconditions for methods of
an interface.
The design approach is implemented in Django web framework and the contracts
generated from the behavioral model are asserted as contracts in the implemented
interface.
A proxy interface is also implemented in Django as a service monitor. This
service monitor can also be implemented for services that are already implemented
and only provide their behavioral specifications in natural language or in any other
form. A service monitor can continuously verify functionality of a service and
reports if a service user violates a precondition or the implementation does not
provide the expected behavior.
5 Beyond CRUD 135
References
Jan Algermissen
Introduction
J. Algermissen ()
NORD Software Consulting, Kriemhildstrasse 7, 22559 Hamburg, Germany
e-mail: [email protected]
coupling between a provider and one single consumer is not a critical situation
whereas tight coupling between a provider and a million consumers on the World
Wide Web is a changeability disaster.
Given this situation, it appears useful to provide a measure for the overall inte-
gration architecture quality of an IT system that expresses how well its component
connections match the circumstances of their use. Such a measure would provide a
way to assess an IT department’s overall resistance to evolution. It could be used to
compare integration architectures or could be tracked over time to verify the success
of an integration architecture management strategy.
This chapter proposes a methodology to define such a quality measure in terms
of the coupling created by the applied connectors on the one hand and in terms of
the specific circumstances of their use on the other.
New requirements often lead to an evolution of the formats used to transfer data
between communicating components. If the applied connectors neither make it
possible to negotiate between new and previous data-format versions nor enable
the transparent use of transforming intermediaries consumers must also be changed
to be able to process the new data format.
In this case, data format changes require implementation activities on the
consumer side which lead to additional coordination cost between consumer and
provider owners beyond the cost of application termination and component re-
deployment.
The complexity of data format changes ranges from simple (for example, adding
a field to an address data structure) to highly complicated (for example, changing the
data model of a data warehouse, impacting the SQL statements of hundreds business
reports).
Connectors that are realized as a set of procedures often have an associated set of
assumptions about the order in which the procedures are called or require relations
between parameter values. Such rules are effectively protocols for the interaction
and the communicating components must share an understanding of these protocols
(Shaw and Garlan 1996).
When the provider changes the rules for the interaction (for example, adds a
method that must be called before a given other method) the consumers must also
be changed to account for the altered protocol.
140 J. Algermissen
Like changes to the data format Connector Protocol Changes result in a require-
ment to change the consumer implementation unless the connector used prevents
protocol changes from affecting the consumer.
(REST’s hypermedia constraint (Fielding 2000, pp. 100) is an example of how
protocol coupling can be removed from the connector interface).
Components use identifiers to refer to other components and the data and control
elements they expose. Some architectural styles remove the need for identity
from the connector interface [for example, Event-Based Integration (Fielding 2000
p. 55)] others provide dynamic identifier resolution (for example, DNS) or runtime
identifier discovery (for example, hypermedia) to reduce the coupling created by
shared identify.
In the absence of such architectural strategies, changes to one component can
lead to a requirement to update the shared identity maintained in other components.
This can result in component configuration changes or programming activity if
identity issues are interweaved with source code.
Common examples of Shared Identity Changes are adjusting database connection
settings, changing relational table- or column names, or updating resource identifiers
of HTTP-based services that expose a fixed set of URIs as part of their service
description.
Some connectors do not specify how coordination is achieved between the processes
of the communicating components or how communication failures are detected and
handled. Instead, these aspects of the communication are deferred to the applications
using the connector.
Changes to one component can significantly change the communication model
and therefore lead to extensive design and implementation changes of other
components.
In the case of components that communicate using a shared file, for example,
concurrency control might be changed from a file locking based approach to explicit
timing assumptions (component A writes at 9 AM and component B reads at 4 PM).
The possibility of communication model changes is typically found in ad-hoc
enterprise integration approaches such as communicating through a shared file or
database table. It is rarely (if at all) found in “modern”, research-based connectors.
6 Quantifying Integration Architectures 141
Connectors
The connector (Fielding 2000, pp. 10) used to mediate communication between
components determines the amount of coupling between them. I will illustrate
the development of the methodology using a set of connectors typically found in
enterprise integration scenarios.
Some of the connector names below also are the names of the corresponding
architectural styles. However, this chapter focuses on the connectors and the amount
of change potentially exposed on connected components.
File Transfer
Shared Database
Remote Procedure Call (Birrell and Nelson 1984) connectors mediate commu-
nication by invoking named procedures over a communication network. Remote
Procedure Call connectors employ a request/response communication model. Call-
ing a remote procedure transfers control and data from one component to another
for the duration of the call. Distributed objects styles also use Remote Procedure
Call connectors.
Common implementation technologies are XML-RPC (Winer 1999), Java RMI
(Oracle 2009), CORBA (OMG 2008), and DCOM (Microsoft 2007). The early
approach to Web services also favored an RPC-style approach (Tilkov 2005).
The primary coupling concern raised regarding Remote Procedure Call connec-
tors is that all components must share an understanding of the specific connector
protocol. Other concerns are decreased understandability because application state
is distributed among the communicating components and potential performance
problems.
Of particular interest in the context of unRESTful uses of REST-based architec-
tures is the realization of Remote Procedure Call connectors by tunneling the remote
method invocation through HTTP requests (Algermissen 2010a).
HTTP Type I
HTTP Type I connectors (Algermissen 2010b) constitute the most common form of
architecturally incorrect use of HTTP. The server component typically specifies a
set of URIs that the client has to know to communicate with the server. In addition
to the set of URIs, the returned and accepted message formats are specified as well
as the service specific status codes to expect. Typically, this information is provided
in a human-(HTML) or machine-readable form [WADL (Hadley 2009)].
While the HTTP methods are used according to their specification there exists
tight coupling between provider and consumer around the service aspects described
in the service description document. The amount of coupling is comparable to the
amount of coupling in the case of Remote Procedure Call connectors.
A prominent example of a service exposing this kind of connector is the Twitter
API (Twitter 2009).
Event-Based Integration
HTTP Type II
REST
The REST architectural style (Fielding 2000) emphasizes overall system simplicity
and decoupling of components. Components communicate through the exchange of
6 Quantifying Integration Architectures 145
The most problematic connectors are File Transfer and Shared Database. Both
cannot protect the communicating components from any kind of change impact. In
addition, all change impacts are equally likely to occur since there are no patterns
or best practices that make any of the changes less likely. These connectors are
closely related to an “ad-hoc” or “do what works” problem solving style – when new
requirements arise, the necessary changes are made without architectural guidance.
Remote Procedure Call and HTTP Type I show similar impact potential. Remote
Procedure Call emphasizes communication through method semantics and change
impact tends more towards connector protocol changes. HTTP Type I on the
other hand emphasizes communication through data format semantics and impact
potential tends more towards data format changes.
Message Oriented Middleware and Event Based Integration generally have less
impact potential due to their ability of temporal decoupling and their focus on
uniform method semantics. Both make it less likely that a possible change actually
impacts a consumer.
HTTP Type I, Message Oriented Middleware and Event Based Integratio all focus
on data centric communication. However, use of standard document formats, for
example, UBL (Bosak and McGrath 2006) seems to be more widely practiced with
the latter two than with HTTP Type I based designs.
The impact potential of HTTP Type II is even lower because the possibility of
HTTP redirect- and content negotiation mechanisms makes it much easier to realize
new provider functionality without impacting consumers in any way. However,
impact is still possible because coupling between provider and consumer exists
around the exposed service description.
REST is the only connector that makes provider evolution completely indepen-
dent from consumer impact. Any kind of evolution can be achieved without causing
any impact on consumers. This is achieved by architecturally removing the need for
any service specific descriptions. Without such descriptions all coupling between
consumer and provider is removed, enabling impact-free evolution.
So far I have presented an approach to capture and compare the effect that
connectors have on the amount of coupling between components. However, the
coupling created by a connector is not sufficient to determine how difficult it is to
change the providing component. We also need to consider how many consumers are
connected through a given connector and how easy it is to coordinate change activity
with them. It is the combination of both, connector coupling and the circumstances
of connector use that determine the effect on the consumer.
If the applied connector matches the circumstances of its use the effect on the
changeability of the provider will be within reasonable bounds but a connector
mismatch can effectively make provider evolution impossible.
6 Quantifying Integration Architectures 147
For example, tight coupling between a provider and a single consumer that are
owned by a single authority is usually not considered an obstacle to evolving the
provider component. On the other hand, any kind of coupling between a provider
and many consumers that are owned by authorities beyond the provider’s control
present a situation where changing the provider must be considered impossible.
In the following sections, I will introduce the concepts of Agency Distance
and Consumer Cardinality to denote how easily coordination between component
owners can be established, and to express how many consumers are tied to a provider
using a given connector.
Agency Distance
Consumer Cardinality
Connector Usage
The two preceding sections introduced the concepts of Agency Distance and
Consumer Cardinality to differentiate several contexts in which connectors can be
used. This differentiation is important because it is not the nature of a connector
alone that determines how difficult it is to change a component on which other
components depend. In fact, it is the balance between the coupling created by a
connector on the one hand and the actual circumstances of how it is being used on
6 Quantifying Integration Architectures 149
the other that determines how a given exposed connector impacts the changeability
of a component.
To classify different contexts of how connectors can be used we combine the
notions of Agency Distance and Consumer Cardinality. This combination results in
the six Connector Usage patterns shown in Table 6.5.
The combinations 1-far, n-far, and N -same are not included because they do
not exist in reality. For example, by definition you cannot have an unknown,
uncontrollable number of consumers within a single agency boundary.
Table 6.6 illustrates the different connector usages with examples.
If the social or business circumstances of an integration scenario make coordina-
tion particularly difficult the connector usages n-near and N-near should be treated
as n-far and N-far, respectively.
Connector Suitability
The goal of the previous sections was to establish the foundation for quantifying the
impact of a given “connection” on how easily and quickly the providing component
can be changed.
We have examined two aspects of “connections”:
1. The potential change impact on the consumer created by the nature of the
connector used.
2. The agency distance and consumer cardinality of the actual use of the connector.
In the following I propose an approach to determine a connector suitability value
based on cascading sets of rules that compare the potential change impact of a
connector with the circumstances of its use and select one value from a set of
connector suitability values.
A connector suitability value expresses how appropriate the choice of the given
connector is compared to the context in which it is used. The following table
describes the four suitability values (Table 6.7) used in this chapter.
I have chosen a set of only four values because it is hardly possible to exactly
determine connector suitability at a finer granularity. I have also chosen not to define
150 J. Algermissen
an odd number of values in order to avoid a medium value that would act as a
meaningless “catch-all”-value for undecided cases. An even number of possibilities
enforces explicit reasoning.
If you find that in your context a higher granularity can be meaningfully
supported the methodology can be adapted accordingly by changing the rule
sets below. However, to enable comparison between systems or to track quality
improvements over time the particular value set and the rules you define are required
to remain stable.
6 Quantifying Integration Architectures 151
The proposed methodology uses cascading sets of rules to determine the suitability
value of a connector in a given context of use. The advantage of an approach that
uses subsequent application of rules is that it enables a refinement of the suitability
value selection at different conceptual levels.
The value selection at the first level is based on the architectural analysis
of the various connectors without considering any particularities of connector
implementation technologies.
The second level allows for refinement of the general suitability values to
reflect implementation technology specific properties. For example, Java RMI and
Web Services, both Remote Procedure Call connectors, have identical general
suitability values but differ significantly when taking the technical properties into
account. While Java RMI requires all components to be implemented in the same
programming language environment Web services provide language independence.
Using the former potentially leads to a programming language change impact while
the latter does not. Implementation technology suitability rules can reflect these
differences by refining suitability values accordingly.
At the third level it is possible to further adjust the suitability values based on
specifics of the application domain or to reflect skills and preferences pertaining to
the context or department in which the methodology is used.
152 J. Algermissen
The general suitability rules for 1-near connector usage are the same as those for
1-same connector usage because the fact that there is only a single potentially
impacted consumer makes all kinds of changes achievable with reasonable cost and
coordination complexity.
6 Quantifying Integration Architectures 153
IT systems exist to support business level processes. Associated use cases are real-
ized as networked applications composed of communicating software components.
Integration architecture management aims to optimize the suitability of the
applied connectors to maintain an evolvable system. The key property of interest of
an integration architecture is how efficiently the integrated system can be changed
to respond to new business requirements.
The notion of component change resistance described in the previous section
can be used to capture this essential IT system property as a measurable entity. The
following table assigns evenly distributed percentage values to the four connector
suitability values with 100% indicating a perfect match (Table 6.12).
Using these percentage values we can express the overall suitability of the
connectors exposed by a component as a fraction of the desired optimum of a perfect
match (100%). For example, the component mentioned in the previous chapter
had an original suitability of 100%. When we added the File Transfer connector
to integrate with several near-distance consumers the suitability of the component
dropped to 0% (critical).
The mapping of suitability values to percentages makes it possible to calculate
the average suitability of a set of components. For example, if we have a system
consisting of five components with the individual suitability values of 100%, 66%,
66%, 0%, and 100% the average suitability can be expressed as 332=5 D 66:4%.
This percentage roughly maps to an average reasonable quality of the integration
architecture.
The better the individual components score the more adaptable the overall IT
system is to requirements for new functionality needed by its stakeholders.
Conclusion
References
Birrell AD, Nelson BJ (1984) Implementing remote procedure call. ACM Transactions on
Computer Systems, 2, 1984, pp. 39–59
Bosak J, McGrath T (2006) Universal business language 2.0. OASIS. http://docs.oasis-open.org/
ubl/cs-UBL-2.0/UBL-2.0.html. Accessed November 2010
Box D et al. (2006) Web services eventing (WS-Eventing). W3C. http://www.w3.org/Submission/
WS-Eventing/. Accessed November 2010
Fielding RT (2000) Architectural Styles and the Design of Network-based Software Architectures.
Doctoral dissertation, University of California, Irvine
Fielding RT (2008) Economies of scale. Fielding, R.T. http://roy.gbiv.com/untangled/2008/
economies-of-scale. Accessed November 2010
Fielding RT (2010) Fielding, Roy Thomas, Message #15819 on rest-discuss mailing list. http://
tech.groups.yahoo.com/group/rest-discuss/message/15819. Accessed November 2010
Fielding RT, Gettys J, Mogul JC, Nielsen HF, Masinter L, Leach P, Berners-Lee T (1999) Hypertext
Transfer Protocol – HTTP/1.1. Internet RFC 2616
Fitzpatrick B, Slatkin B (2010) PubSubHubbub Core 0.3 – Working Draft. Google Inc. http://code.
google.com/apis/pubsubhubbub/. Accessed November 2010
Google (2010) Google calendar API. http://code.google.com/apis/calendar. Accessed November
2010
Hadley M (2009) Web application description language. http://www.w3.org/Submission/wadl.
Accessed November 2010
Hophe G, Woolf B (2004a) Enterprise Integration Patterns. Pearson Education. p. 43
Hophe G, Woolf B (2004b) Enterprise Integration Patterns. Pearson Education. p. 47
Khare R, Taylor RN (2004) Extending the Representational State Transfer (REST) Architectural
Style for Decentralized Systems, in 26th International Conference on Software Engineering
(ICSE), (Edinburgh, Scotland, 23–28 May 2004)
Klensin J (2001) Simple mail transfer protocol. http://www.ietf.org/rfc/rfc2821.txt. Accessed
November 2010
Microsoft (2007) Distributed component object model. Microsoft. http://msdn.microsoft.com/
library/cc201989.aspx. Accessed November 2010
Microsoft (2009) Message queuing MSMQ. Microsoft. http://msdn.microsoft.com/en-us/library/
ms711472(VS.85).aspx. Accessed November 2010
Millard P, Saint-Andre P, Meijer R (1999) XEP-0060 Publish-Subscribe. XMPP Standards
Foundation. http://xmpp.org/extensions/xep-0060.html. Accessed November 2010
OMG (2008) Common object request broker architecture. Object Management Group (OMG).
http://www.corba.org/. Accessed November 2010
Oracle (2009) Java remote method invocation. http://www.oracle.com/technetwork/java/javase/
tech/index-jsp-136424.html. Accessed November 2010
Shaw M, Garlan D (1996) Software Architecture: Perspectives on an Emerging Discipline.
Prentice-Hall, Englewood Cliffs, NJ, USA. p. 169
Sun (2008) Java Message Service (JMS). http://www.sun.com/software/products/message queue/
index.xml. Accessed November 2010
Tilkov S (2005) RPC style web services. http://www.innoq.com/blog/st/2005/05/18/rpcstyle web
services.html. Accessed November 2010
Twitter (2009) The Twitter API. http://apiwiki.twitter.com/Twitter-API-Documentation. Accessed
November 2010
Winer D (1999) XML remote procedure calls. http://www.xmlrpc.com/spec. Accessed November
2010
Chapter 7
FOREST: An Interacting Object Web
Duncan Cragg
Abstract FOREST satisfies the need for objects to easily interact across the
network in a RESTful way – without calling methods on each other. To do this,
it asks you to set your objects up in an Observer Pattern relationship. Or, in
particular, a “Functional Observer Pattern”, where an object’s state is set as a
Function of its current state plus the state of other objects it Observes through links.
This observation occurs through either pull or push of linked object state. Such a
programming model maps directly to RESTful distribution over HTTP, using GET
for pull and POST for push of object state, in both directions between interacting
servers. Objects are published into a global interacting object Web. This distributed
object architecture is declarative in nature, and thus very expressive, as well as being
naturally concurrent.
FOREST satisfies the need for objects to easily interact across the network in a
RESTful way – without calling methods on each other. To do this, it asks you to set
your objects up in an Observer Pattern relationship. Or, in particular, a “Functional
Observer Pattern”.
FOREST is an acronym for “Functional Observer REST”. Once objects are in a
Functional Observer relationship, RESTful distribution or integration becomes very
simple, as there is essentially a one-to-one mapping from the Functional Observer
model to REST’s Hypermedia Constraint.
FOREST is thus a distributed object pattern – distinguished by its style of object
interaction. It describes a Web of interlinked, interacting, interdependent object
resources, hosted across multiple applications or servers.
D. Cragg ()
ThoughtWorks (UK) Ltd., Berkshire House, 168–173 High Holborn, London, WC1V 7AA
e-mail: [email protected]
Functional Observer means that these objects interact by setting their next state
as a Function of their current state plus the states of other objects Observed near
them in the Web and on which they depend. Observation may occur either by pull
or by push of object state.
This observation is enabled across the network by an HTTP layer using just GET
and POST, in a “symmetric REST” style, conforming to the constraints of REST
(Fielding 2000). A server may become a client in order either to GET or pull a
remote object resource for its own dependent object resource, or to POST or push
its own object to a remote dependent object. Another way of looking at this is that a
client becomes a first-class server to publish its own object resources.
Although an unusual object interaction pattern at the programming language
level, the Functional Observer model is actually very easy to program due
to its declarative, functional, reactive and asynchronous programming style.
Functional Observer objects are programmed independently as “masters of their
own evolution”. It is similar to approaches found in the Clojure and Erlang
programming models, and may be readily implemented over the asynchronous
Node.js framework, as well as mainstream languages such as Java.
This object independence makes Functional Observer object interactions easy
to distribute, both across application partitions – inheriting the interoperability,
evolvability and scalability benefits of REST – and across multicore, without the
usual concerns around threads and locks.
In the Functional Observer Pattern, an object sets its own next state as a Function of
the object states it Observes in itself and through its links at any time (Fig. 7.1):
It is beyond the scope of this chapter to discuss the history and origins of the
Functional Observer model and its place within the broad scope of programming
models, patterns, styles and paradigms. We will simply point out some similarities
and mention some languages that support implementation.
The Functional Observer model is somewhat related to Dataflow, Reactive
and Functional Programming styles, although it can be readily implemented in
mainstream languages. It has some similarities to, and perhaps may be implemented
by, Clojure’s Agents and Watchers (Hickey 2009). Similarly, implementations of the
Actor Model, including Erlang (Armstrong et al. 1996), may support the Functional
Observer Pattern. A useful, but more basic, infrastructure for implementation
is provided by the “Node.js” asynchronous, server-side Javascript framework
(Dahl 2009).
Functional Observer objects interact in a declarative, reactive and asynchronous
way with other objects. A Functional Observer object never directly tells another
what to do by calling methods on it. (It may strongly imply a preference directed
at another, however, which can have a similar effect, but most often that style
of interaction is not needed.) This switch from imperative to declarative thereby
causes a corresponding inversion of the Object-Oriented mantra, “Tell don’t Ask”
(Cragg 2009).
164 D. Cragg
The familiar model of method-calling that is used for object interactions in common
programming languages is, of course, not resonant with distribution in the REST
style. We identify this method-invocation interaction style as “imperative”. RPC is
an example of this style when attempted over the network.
Functional Observer’s declarative object interaction style, on the other hand,
is resonant with REST, and maps straightforwardly onto RESTful use of HTTP;
and in particular onto the Hypermedia Constraint, as we will show. Correct REST
distribution or integration has often been seen as a tricky art, so there is a huge
advantage in having a simple and powerful programming model where RESTfulness
almost “drops out” (Fig. 7.2).
7 FOREST: An Interacting Object Web 165
This will all become much clearer with a real example. Rather than dig into how
a programmer sees the Functional Observer Pattern play out, with all the details
of implementation languages and programming styles, it will be enough simply to
watch what happens “on the wire” in HTTP messages, as some objects held on
different servers interact with one another.
This will bring out the detail of both the Functional Observer interactions and the
application of the constraints of REST in FOREST. The second part of this chapter
will then show in detail how FOREST meets the Hypermedia Constraint, which is
a little more complex than can be explained by way of this example. The Stateless
Constraint is also left to be discussed in that context.
We’ll demonstrate with a Foreign Exchange order fulfilment scenario. This will
have an Order server holding Orders and a Fulfilment server holding fulfilment
status as Tickets. The Order server can also hold Payments. Hence, in the Functional
Observer style required by FOREST, Orders may observe Tickets and Tickets may
observe Orders and Payments.
First, an as-yet-unseen Order in the Order server (fx-orders.com) observes, and
thereby fetches, a known, top-level “Dealer” object from the Fulfilment server (fx-
broker.com):
HTTP/1.1 200 OK
Etag: "313"
Cache-Control: max-age=10
Content-Type: application/json
So: which is the client and which is the server? In this scenario, as we will see, the
Order server can be a client of the Fulfilment server and vice-versa.
7 FOREST: An Interacting Object Web 167
Identification
is the “locator” aspect for where that uniquely- and universally-identified object
can always be found. Indeed, any other characters of a URL are then essentially
redundant, including “.json” or “.xml”, other path elements, etc.
Further, given that the UUID or GUID is universally or globally unique, it is
certain that a representation or copy of the object referred to could also be found
cached in any one of a number of other hosts – perhaps keyed by the unique object
id alone. It is the ability to reliably find or locate an object representation by a unique
identifier that is the essential characteristic we need.
We are using JSON for our serialisation of objects into their representations – the
Content-Type is application/json – as it is simple and clear, and a better match for
the kind of data we prefer to program our objects with.
This also allows us to conform to REST’s Self-Descriptive Constraint for Media
Types as this is a common, standardised format, widely understood by available
libraries and frameworks.
The purpose of the Content-Type header at the HTTP layer is to give broad
direction to choose processing modules within which most of the actual content
interpretation happens, once that module starts reading inside the content itself. In
the content layer, there will always be an understanding between client and server
that goes beyond the Media Type and into business or domain interactions.
For example, there is a channel of communication set up between an author of
plum jam recipes and their plum-picking readers, carried through HTML. On an
e-commerce Web site selling plum jam, HTML is exchanged such that the site can
have an e-commerce interaction with the jam-consuming end-user. That exchange
is carried by, or executed through, the base HTML Media Type.
There is not one Media Type for recipes, and another for buying jam! Minting
new Media Types, maybe one or more Media Types per application – perhaps as
“vnd.” or “ Cxml” types – compromises self-descriptiveness.
At the HTTP level on the Web, the Content-Type is a very broad and coarse
label, which has the great advantage of self-descriptiveness: REST requires that
we have few Media Types understood as widely as possible; including by installed
libraries and applications. Our guidance on Media Types is to follow the crowd –
even, indeed, in preference to following a standard.
So we should use a very common base type, called out in HTTP’s Content-
Type, and have all the rich domain-level semantics up inside the content, driving
the Functional Observer interactions. Hence, we could re-use XML or XML-based
types such as XHTML1 or XHTML5 or Atom and AtomPub to serialise objects.
More appropriately and simply for our data-oriented applications, we could output
JSON representations of the internal object resources. Or we could use content
negotiation to choose the serialisation.
7 FOREST: An Interacting Object Web 169
But JSON is very bare and basic compared to XHTML. As we gain experience,
we could aim to settle on a single, common, standardised sub-Media Type of JSON,
with various domain-specific formats or schemas inside that type – such as our
Orders, Payments and Tickets. Perhaps we may call it “application/forestCjson”,
following the “Cxml” convention.
All this depends to some extent on how you view the strictness of the Self-
Descriptive Constraint with respect to Media Types, which Fielding has called out
as something of a frustratingly variable constraint in REST (Fielding 2006).
As a publisher, unless you make a reasonable attempt to re-use all or part of any
formats or schemas within XML, XHTML or JSON that are in wide use or being
standardised, including Microformats, etc., you are still reducing your conformance
to REST’s Self-Descriptiveness Constraint. You still need to be aware of the trade-
off of precision versus re-use that this implies.
As long as the base Media Type is conformed to, this re-use can be in the form
of basic instantiation, sub-classing or extending. Also, the base type can be used as
a carrier for another type, in the way Microformats, RDFa or Microdata are carried
by XHTML1/5 and content is carried by Atom. It may also take the form of just
re-using parts of existing standards.
On the client side, however, different recipients of such data see things their own
way. Class is in the eye of the beholder, not synchronised through shared libraries.
This allows decoupling and independent evolution.
The way a Media Type is interpreted or processed is entirely up to the client. The
server is signalling what it thinks this content is in general terms, but the client can
and will interpret that Media Type however it likes given its current state and goals.
Whenever you fetch a JSON- or an XML-based object, the schema above that base –
i.e., where you expect to find the data you were looking for – will always depend on
the URL you fetched it from, the context around that link, and the use you expect to
make of it.
In the spirit of Postel, decoupling is enhanced through a server’s respect of
standards in its published data, along with a client’s tolerance of the incoming type –
just taking what it understands and ignoring anything else, perhaps by using XPath
or an equivalent approach in JSON.
In our JSON content, we’ve chosen a tagging system for creating class-like
subtypes of the base Media Type. The “fx” and “dealer” tags give us flexible, loose
typing which sets our expectations about how we interact with this object, from
reading some documentation and conformance tests. The aim would be to settle on
a number of common JSON schemas or grammars, using such conventions, within
our “application/forestCjson” Media Type.
170 D. Cragg
REST does not talk much about the subject of methods, except to say that they
should form a uniform interface and that they should be well-known.
As we’ve already described, our use of GET and POST is entirely for state
transfer in each direction – initiated by either side. This is pretty conformant to
Self-Descriptiveness, as the Web works much like that. The idempotency of POST
in FOREST can be signalled by use of our “application/forestCjson” Media Type.
Using PUT and DELETE can actually fail us in self-description of messages,
since much HTTP code in the wild does not handle them. However, of course, they
are not necessary for the Functional Observer Pattern.
Correct use of common HTTP headers and response codes gives proxies and
clients a chance to cache content and to know when things have gone wrong in
the state transfer. We expect to see the usual response codes: “200 OK”, “303 See
Other”, “304 Not Modified”, “404 Not Found”, and others.
Further helping self-descriptiveness and separation of concerns, these headers
and return codes should be given as closely as possible their common meanings
regarding just the state transfer of representations. In FOREST, we do not modify
their meaning in any way on a domain-specific basis. Thus “200 OK” means the
state transfer was successful – even if that state indicates an “error mode” at domain
level, in a Functional Observer object exchange.
Although we will revisit the Hypermedia Constraint later, we still need some
hypermedia to constrain! In fact, in FOREST, our hypermedia is more in the nature
of “hyperdata”. Hyperdata means having our data linked up into an object Web or a
graph of objects.
Here, in the response content representing the Dealer object, we see that the
JSON object returned has URLs inside JSON strings. It is currently dealing with a
number of Tickets, listed within it.
These links are created in a fairly obvious way. Presumably our Dealer object
links internally to these Ticket objects. So when serialised into a Dealer represen-
tation, those links can simply be converted to URLs containing the Ticket objects’
unique ids. As we’ll see below, the Ticket object will also point by URL to its
corresponding Order object over on the Order server – which points back – thus
completing a cross-server, hyperdata object Web.
Now, declaring that a URL found in a JSON string is hyperdata is hardly some-
thing worthy of an RFC, but that would be part of any “application/forestCjson”
JSON hyperdata standard. Similarly, you may prefer XHTML1/5 to XML, as it
comes with a built-in link semantics, where XML would need to be enhanced with
XLink.
Links in FOREST only represent such declarative data structuring, and therefore
always point to fetchable object resources. Link relations may be used in XHTML
7 FOREST: An Interacting Object Web 171
or XML as part of the serialisation of the structure of an object linked to another, but
the entire surrounding context of a link, plus the goals and intents of the observer,
give the link semantics, not just a single relation tag. Finally, a link may sometimes
just have to be fetched before you can really know what it meant!
As long as all of your interacting servers are able to discover and use the links
they need that are in the data, guided by surrounding context, that is all that matters.
Thus, we can see and traverse links in our hyperdata. We have a distributed graph
of objects; a hyperdata object Web, both created and consumed by the applications
being integrated.
After that very long detour, triggered by a simple GET, things should go a little
quicker now in our Foreign Exchange example. Here is that GET by the Order
observing the Dealer again:
GET /dealer123 HTTP/1.1
Host: fx-broker.com
HTTP/1.1 200 OK
Etag: "313"
Cache-Control: max-age=10
Content-Type: application/json
{ "%url": "http://fx-orders.com/ordr321",
"tags": [ "fx", "order" ],
"params": [ "usd/jpy", "buylim", 81.7, 500.00 ],
"dealer": "http://fx-broker.com/dealer123"
}
172 D. Cragg
This JSON Order object includes its own URL at the Order server, with a
preceding “%” on the tag as a convention indicating a metadata field. Such fields
are candidates for including in the HTTP headers; the URL could be included as
a “Content-Location” header, for example. This depends on your tolerance of non-
standard HTTP header usage.
The appearance of this URL reflects firstly, that this is a first-class object
available on the Order server whose state is being pushed, and secondly, that this
POST is idempotent, as are all FOREST POSTs, because reporting the latest or
current state is an idempotent operation. This POST is a state declaration; it is
idempotent in intent – the Order is just telling the Dealer of its current state –
implying that it is ready to be told about a corresponding Ticket. POST is state
transfer in FOREST, not an event, message, action or command. The role of POST
will be discussed further below.
The “dealer” URL in the Order object indicates that this is an Order for this
Dealer, no other. The Order has to stand independently, declaratively; potentially
fetched by others using GET. There will be many such links in Functional Observer,
since interactions within and through an object Web is fundamentally how it all
works.
The order itself is for a USD/JPY exchange – “buylim” is short for “buy limit”
which means buy when the price drops far enough – below 81.7 here.
On the Fulfilment server side, there is a constraint or rule on the Dealer that
ensures it interprets this incoming POST as a state declaration, not a command that
could result in multiple Tickets: “if I observe an Order pointing to me that does not
have a link to a Ticket, I must make sure I have a Ticket somewhere in my list that
points to this Order”. Such rules work off state, not state change, so can be re-run
repeatedly.
So, within the Fulfilment server, the Dealer object sees the incoming Order object
and creates a new Ticket object, adding that object to its list.
Then it is up to the Ticket to carry on the conversation with the Order. The Ticket
object is now a “live” object, responsible for its own evolution. Once the Ticket has
sorted itself out, it needs to tell the Order object about itself.
A POST response is something of an open channel for now returning state. The
HTTP RFC is rather vague about what is returned from a POST. In theory, it would
be possible to always return a “204 No Content” empty response to all POSTs, and
then POST back any follow-up updates separately. But that would be a waste – it
is more efficient to use this opportunity to update the POSTing server immediately
with any new state that has occurred as a result of the incoming POST.
So, the most likely response to a POST, and usually the most useful, is for it to
act exactly as if it were a GET on the POST URL target. It returns a 200 code and
sets the Content-Location header to its own URL, to indicate that this response is
intended to be seen as equivalent to a GET (Fielding et al. 2011). This gives the
target a chance to immediately and efficiently return in the response any new state
that was triggered by the incoming object POST.
7 FOREST: An Interacting Object Web 173
Here is such a response that we could get to the POST on the Dealer, showing
our new Ticket object in its list:
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/dealer123
Etag: "314"
Cache-Control: max-age=10
Content-Type: application/json
But in this case, it is not telling us much. Alternatively, we could return another
object that is considered a dependency of that incoming object, either through the
same 200/Content-Location approach, or through a 303 redirect, also containing
the object itself to save a round-trip. In this example, the Ticket object itself would
actually be more useful to us, instead of just the Dealer pointing to it:
HTTP/1.1 303 See Other
Location: http://fx-broker.com/tick111
:
or:
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/tick111
Etag: "1"
Cache-Control: max-age=10
Content-Type: application/json
{ "%url": "http://fx-broker.com/tick111",
"tags": [ "fx", "ticket" ],
"order": "http://fx-orders.com/ordr321",
"params": [ "usd/jpy", "buylim", 81.7, 500.00 ],
"ask": 81.9,
"status": "waiting"
}
{ "%url": "http://fx-orders.com/ordr321",
"tags": [ "fx", "order" ],
"params": [ "usd/jpy", "buylim", 81.7, 1000.00 ],
"dealer": "http://fx-broker.com/dealer123",
"ticket": "http://fx-broker.com/tick111"
}
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/tick111
Etag: "2"
We are in luck, the market is still heading down. The Ticket is updated
accordingly: its state is a function of the params in the order, combined with its
internal access to the Foreign Exchange market.
Time passes. Anxiously, we poll to see if we missed anything because of a
dropped POST:
{ "%url": "http://fx-broker.com/tick111",
"tags": [ "fx", "ticket" ],
"order": "http://fx-orders.com/ordr321",
"params": [ "usd/jpy", "buylim", 81.7, 1000.00 ],
"ask": 81.6,
176 D. Cragg
"status": "filled"
}
Now, while waiting for that we started to feel even more confident in our
USD/JPY prediction, and wanted to bet on an even cheaper price. However, we
now have a race condition:
{ "%url": "http://fx-orders.com/ordr321",
"tags": [ "fx", "order" ],
"params": [ "usd/jpy", "buylim", 81.5, 1000.00 ],
"dealer": "http://fx-broker.com/dealer123",
"ticket": "http://fx-broker.com/tick111"
}
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/tick111
Etag: "4"
{ "%url": "http://fx-orders.com/ordr321",
"tags": [ "fx", "order" ],
"params": "cancelled",
"dealer": "http://fx-broker.com/dealer123",
"ticket": "http://fx-broker.com/tick111"
}
7 FOREST: An Interacting Object Web 177
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/tick111
Etag: "5"
{ "%url": "http://fx-orders.com/ordr321",
"tags": [ "fx", "order" ],
"params": [ "usd/jpy", "buylim", 81.7, 1000.00 ],
"dealer": "http://fx-broker.com/dealer123",
"ticket": "http://fx-broker.com/tick111"
}
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/tick111
Etag: "6"
Not too late. Notice how this is all state-driven, not event-driven. All depen-
dencies are state-dependencies. We are just applying business domain rules or
constraints over dependent state. And in this case, as long as the back-end systems
still allow the order to be filled at the stated conditions, we are on. There is no rigid
178 D. Cragg
{ "%url": "http://fx-orders.com/ordr321",
"tags": [ "fx", "order" ],
"params": [ "usd/jpy", "buylim", 81.7, 1000.00 ],
"dealer": "http://fx-broker.com/dealer123",
"ticket": "http://fx-broker.com/tick111",
"payment": "http://fx-orders.com/paym432"
}
Now the Ticket, that can see this new Order state, needs to traverse the “payment”
link to see it, to determine its next state – hopefully to “paid”. Hence there is no
change just yet to the Ticket, so it returns a 204, then fetches the Payment:
GET /paym432 HTTP/1.1
Host: fx-orders.com
HTTP/1.1 200 OK
Etag: "1"
{ "tags": "payment",
"invoice": "http://fx-broker.com/tick111",
"order": "http://fx-orders.com/ordr321",
"amount": 81600.00,
"account": { .. }
}
We could have POSTed this Payment to the Ticket instead, after POSTing the
Order pointing at it. It is only shown this way as a reminder that the state transfer is
essentially independent of which server initiates it.
If we POSTed, the idempotency of that FOREST state transfer would ensure
multiple submissions were ignored, assuming the server co-operates. Again, there
is probably a rule in there on Ticket that says: “If I’m aware that there is a Payment
object pointing to me and I’m unpaid, take the payment (once) using that Payment
object”.
Notice that this can be a generic, non-Foreign Exchange domain, payment format
or type – it does not say “fx” in the tags. And we can use normal Web security such
as Auth headers, TLS, etc., to make this secure.
7 FOREST: An Interacting Object Web 179
{ "%url": "http://fx-broker.com/tick111",
"tags": [ "fx", "ticket" ],
"order": "http://fx-orders.com/ordr321",
"payment": "http://fx-orders.com/paym432",
"params": [ "usd/jpy", "buylim", 81.7, 1000.00 ],
"ask": 81.6,
"status": "paid"
}
That example showed how Functional Observer REST works, and how it meets all
of the REST constraints, apart from two constraints not yet covered: the Hypermedia
Constraint and the related Stateless Constraint.
It turns out that the Hypermedia Constraint maps right on to the Functional
Observer programming model.
Stateless Constraint
Stateless means that the server holds no ongoing state between client requests to
track or in any way drive or co-ordinate a succession of such client requests or
anything else about the client, beyond offering responses on demand, containing
links to more resources. Each request is seen as independent by the server at the
HTTP level, and any state held across requests is only in the state of its own
resources.
In FOREST, object resources may establish a relationship with “client-side”
objects, but the interactions, inter-links and state are out in the open in the content,
not hidden away at the HTTP interaction level, or in any client-specific session state.
The HTTP layer of FOREST only handles the mechanical mapping of Functional
Observer pulls and pushes between domain-level object resources into one-shot,
independent GETs and POSTs.
So if the server is not holding state for the client, the client has to do all of
its own co-ordination in the face of the server resources it sees. A client has its
180 D. Cragg
own “application state” to guide its working through the hypermedia Web before
it. Indeed, hypermedia is the “engine” of this application state in REST – the
Hypermedia Constraint.
The Hypermedia Constraint thus works in hand with the Stateless Constraint,
since server statelessness with respect to clients leaves its hypermedia as the only
influence it has on client or application state.
Hypermedia Constraint
The Order server provides hypermedia to the Fulfilment server, in the form of an
Order which links to a Payment, so in that case, it is the Fulfilment server whose
application state we want to be dependent on this Order server hypermedia. The
Fulfilment server is akin to the search engine crawler in this way.
So what exactly is the “application state” in the Fulfilment server?
Consider what depends on the Order server’s hypermedia: the Fulfilment server’s
Ticket, corresponding to the Order it has been given, is dependent on both that Order
and its linked Payment. So the Fulfilment server’s Tickets are also its application
state. There is no other state that is significant here. The Ticket can hold links to
the other object resources that it is working on or cares about; Tickets hold links to
Orders and Payments.
Driving Ticket lifecycle is the entire purpose of the Fulfilment server, just
as rendering documents is the entire purpose of the browser, and collecting and
indexing pages is the entire purpose of the search engine crawler.
And like the crawler through the search engine server, we can publish the
application state we have evolved to – the Tickets – as more resources, more
hypermedia.
For us in our fulfilment scenario, the Hypermedia Constraint quickly boils down
to: the current state of a Ticket depends on the state of its Order and Payment. And,
in the other direction, when the Order server is being the client, the Order depends
on the Ticket, to see how it is being fulfilled and to make the payment when it is
ready.
Which, of course, is another way of describing the Functional Observer Pattern.
In other words, we meet this REST constraint in FOREST simply by following the
Functional Observer model, ensuring that the states of the objects in our hyperdata
graph published by our integrated applications are dependent on the states of other
objects around them, discovered through links. HTTP is used as the pipework of
that engine, to move object state around.
Or, to paraphrase for FOREST: “Hyperdata as the Engine of Hyperdata”. Which
is exactly the Functional Observer model. Our use of Functional Observer, when
distributed, gives us the Hypermedia Constraint, which, when distributing over
HTTP, pretty much delivers all of the remaining REST constraints, too.
We have an interacting, interdependent, interlinked object Web. Each object in
that Web is independent while also interdependent: the master of its own destiny,
deciding how to evolve by itself, based upon the hyperdata context it finds itself
within – the context set by other, similarly independent yet interdependent objects.
182 D. Cragg
The Hypermedia Constraint is largely GET-oriented. The Fulfilment server can GET
the Order that a Ticket it hosts links to, or its linked Payment, from the Order server,
because that Ticket depends upon them. The Order server may GET the Ticket,
because the Order depends upon it.
However, in Functional Observer, we have push by POST as well as pull by GET.
As we have seen, the Order server will also POST the Order directly to the Ticket on
the Fulfilment server; and, indeed, that is what one would expect to be the normal
flow of events when one server has something to say to the other. It is more efficient
to push than to pull or poll when things are changing.
But how does such a POST of an object resource representation fit into the
REST constraints? What are the responsibilities of POST in this scenario and in
this interacting object Web interpretation of REST?
As already noted, REST has little to say on the actual methods we use. The
general consensus in the REST community seems to be that POST can be used in
pretty much any way you like, if you are not using its data-editing interpretation as
“create a new entry in a collection”.
Since REST has little to say on the subject of the workings of POST, we could
look at the HTTP spec, (Fielding et al. 1999), which currently says something
about “subordinates”, alluding to the create-new role, but also has a catch-all “data-
handling process” function, which is not especially useful to us. This is one of the
areas that may be clarified by the HTTPbis working groups (Fielding et al. 2010).
So, we turn finally to the way the Web works, and it all actually becomes very
simple, even to fit POST back into the REST terminology.
On the Web, what we can POST, and to where, is set up for us with forms. Forms
supply domain-specific annotation and structure, as well as a URL to POST to.
Presenting a form and having the user fill it in is entirely within the realm of
application state. That we got a form at all is an example of hypermedia being an
engine of that state.
This application state then makes its way back to the hypermedia realm through
the submit URL, and in any ongoing redirects and pages that depend on the
submitted form.
7 FOREST: An Interacting Object Web 183
Thus, in REST terms, POST is used when certain application states are reached,
to send a little of that application state back into the hypermedia graph. That
hypermedia may then change, in resource state or link structure, to drive our
application state in a different direction. It is “hypermedia as the engine of an
element of application state that then acts as an engine of hypermedia”!
So, in our scenario, where application state comprises first-class object resources,
this becomes even more straightforward. The Order server knows, in the face of
Ticket hypermedia or hyperdata, that it can POST an Order, as its submission of a
part of its own application state, to the Ticket on its URL. Then the Ticket and its
local hyperdata can change as a result of this POST; perhaps then driving the Order
application state that depends on it in a different direction. Similarly, the Ticket can
be POSTed into Order hyperdata, which may also react.
The Order server knows that it can push the Order to the Ticket because it is part
of the domain interaction specification for Order and Ticket objects – the Order
itself drives the push of its own state. This is the equivalent in automatic business
or domain logic of a human driving an interaction, reading and filling in forms. The
logic that determines the dependency of an Order on a Ticket is the same logic that
determines that that Ticket is now likely to be interested in being POSTed the current
Order state.
Indeed, that the Ticket may itself be dependent on that Order. From the Ticket’s
point of view, as application state that depends on Order server hyperdata, it is
continuing to meet its obligations under the REST Hypermedia Constraint to be
dependent on the Order hyperdata, but instead of using GET to pull it, it is being
pushed the Order, including its own URL for future GETs and perhaps with a
hyperlink to the Payment.
It runs its own domain logic over the hyperdata graph visible in front of it, and
this logic is indifferent to whether that hyperdata was pulled or pushed into view. Of
course, once an object with its URL has been seen from a push, it is always possible
to pull or poll on that URL, as long as it is saved as a link back.
Thus the initial POST is the key event – once the target has received that, it takes
over responsibility for its dependency on the incoming object. Subsequent POSTs
are simply timely notifications of state change when the pushing object wants to
take responsibility for that. Otherwise, the target can poll when it is interested.
Optimising POST
That concludes the description of the mapping between Functional Observer and
REST’s Hypermedia Constraint over HTTP, via the mapping from pull and push
184 D. Cragg
observation to GET and POST. It is reassuring that this often tricky constraint of
REST can be met easily by using the simple and powerful Functional Observer
object programming and interaction pattern.
It is worth now exploring the role of POST as idempotent object push in
FOREST, as there are some optimisations that can be made, knowing how it is used.
We have a clear role for POST in FOREST: to push an updated object state to other
objects that depend on it – an object that is actually hosted by the source of the
POST request and could otherwise be pulled or polled to meet those dependencies.
In this role POST is now idempotent, as it is effectively a “reverse GET”. We can
push an object’s current state as much as we like in the same way that it could be
repeatedly fetched idempotently by GET. To enable this idempotency and symmetry,
the POSTed object must of course be self-descriptive enough to include its own
URL.
Thus in FOREST a POST request is much the same as a GET response: it has a
Content-Length, Content-Type and body. Since it carries the POSTed object’s URL,
it can be pushed into the client-side cache of the target’s server for future GET
requests. So to finish off this “POST request as GET response”, it could carry cache
information, too.
The main cache parameters needed are Etag and max-age. These could go
alongside the URL in the object itself, in a metadata section:
POST /ordr321 HTTP/1.1
Host: fx-orders.com
Content-Type: application/json
{ "%url": "http://fx-broker.com/tick111",
"%etag": 1, "%max-age": 10,
"tags": [ "fx", "ticket" ],
"order": "http://fx-orders.com/ordr321",
"params": [ "usd/jpy", "buylim", 81.7, 500.00 ],
"ask": 81.9,
"status": "waiting"
}
But, as mentioned above, these metadata parameters are candidates for pushing
down into HTTP headers; into the POST request headers, unconventionally, with
the URL as a “Content-Location” header:
POST /ordr321 HTTP/1.1
Host: fx-orders.com
Content-Location: http://fx-broker.com/tick111
7 FOREST: An Interacting Object Web 185
Etag: "1"
Cache-Control: max-age=10
Content-Type: application/json
Now, what if there were two objects in one host that both depended on the same
remote object? The framework driving those two objects could clearly save time and
bandwidth by fetching the remote object dependency just once for both of them. It
could put that object into the client-side cache, then show it to both dependents. It
could then re-use the cached object immediately if a third object also looked at it.
Things get a little more complicated when the dependency pushes itself at those
two objects. After doing this the first time, targeting each dependent, it would be
wasteful to carry on POSTing twice per update into their common host.
Instead, it would be better if the object were pushed once, at one of the two
objects, and, as in the GET case, put into the client-side cache, then distributed to
the other dependents. That one POST request could be directed at the URL of one
of the dependents at random, or at the dependent whose expected response is most
interesting or needed most promptly.
But how does the host or framework of the remote object know that two of its
dependents are on the same host, or share the same client-side cache? You cannot
just assume two URLs with the same host:port actually point to the same back-end
host; that could be a reverse proxy.
One solution is to return a unique cache identifier in the “Server” header of POST
responses, to allow such correlation and bundling in future. Another solution is to
add a new header in POST responses, perhaps “Cache-Notify”, which not only
serves the same purpose of uniquely identifying that shared cache, but does that
by offering a common URL that can be POSTed to, for all objects that return it.
186 D. Cragg
The object returned from a POST to this Cache-Notify URL would now be in the
hands of that server – perhaps the first dependent notified that reacted or updated.
Almost equivalent to Cache-Notify would be a URL set up per incoming object –
effectively its URL in the cache. Then you would actually use PUT to set the state
of that cache “resource”, and would not need the URL on the POSTed object itself.
For un-observing, in the first approach, a 403 could be returned if the object
chosen lost interest, meaning the next POST should go to the next dependent sharing
that Server header. In the second and third approaches, a 403 would mean there were
no more dependents of the POSTed object currently left on this host, being served
by that Cache-Notify or per-object URL.
All of this is just optimisation that would be implemented by the framework to
keep it transparent to the object programmer, and none of it is required in FOREST.
Finally, the “Cache-Notify” header can be added to GET requests, to request a
“subscription” to future changes in that target URL. This is a host-level agreement
that does not involve any individual objects; the subscribed object would be unaware
of the propagation of its updates. It is thus quite a different thing from the object-
initiated form above. Indeed, it amounts to the generic form of network Publish-
Subscribe. Fielding has rejected Publish-Subscribe on the Web (Fielding 2008), and
this is an optional optimisation in FOREST that can be used to keep cluster caches
fresh, etc.
Asymmetric “API”s
Sometimes you really are in an asymmetric situation and your clients are not able
to host their own objects. Then the server side of this becomes more like an “API”.
FOREST can support this asymmetric style of server-centric APIs.
The server carries on publishing its own Web of cacheable objects for the client
to GET. The client can then continue to use Functional Observer to maintain the
dependencies of its unpublished objects on those server-side objects.
But what about POSTs of those client objects, when there are no client URLs to
include? How do server objects know that a POSTed object is the one they depend
on and that they’ve seen before, without a URL to identify it?
The trick is simple: instead of the client sending the URL of its object in a POST,
it just sends its unique id. Let us call that a “UID”, and say that it could be a UUID
or a GUID. Here is what the Order POST would look like now:
POST /dealer123 HTTP/1.1
Host: fx-broker.com
{ "%uid": "uid-a321-6fb3-129af3d",
"tags": [ "fx", "order" ],
"params": [ "usd/jpy", "buylim", 81.7, 500.00 ],
"dealer": "http://fx-broker.com/dealer123"
}
7 FOREST: An Interacting Object Web 187
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/tick111
Etag: "1"
The UID is prefixed with “uid-” to make its “type” immediately clear. Now, as we
see here, with this approach we have to return the Ticket for this Order immediately.
The rest of the interaction is much the same, only with more polling:
POST /tick111 HTTP/1.1
Host: fx-broker.com
{ "%uid": "uid-a321-6fb3-129af3d",
"tags": [ "fx", "order" ],
"params": [ "usd/jpy", "buylim", 81.7, 1000.00 ],
:
}
HTTP/1.1 200 OK
Etag: "3"
"status": "filled”
}
{ "%uid": "uid-a321-6fb3-129af3d",
"tags": [ "fx", "order" ],
:
"payment": "uid-03de-008a-eff20d7"
}
{ "%uid": "uid-03de-008a-eff20d7",
"tags": "payment",
"order": "uid-a321-6fb3-129af3d",
:
}
HTTP/1.1 200 OK
Content-Location: http://fx-broker.com/tick111
Etag: "7"
You may think you need an API to allow direct editing of a server’s resources. But
in the majority of cases, it is better to think a level higher – to think in terms of
what you actually want to do in domain or application terms, and design interacting
objects that declare their own higher-level meaning and intents. That is where the
Functional Observer and FOREST approaches work best.
But what if you really do want a data editing service, offered through a tradi-
tional, asymmetric API? Using HTTP RESTfully using the traditional, four-method
protocol style typified by AtomPub runs the designer into issues of ownership and
partial ownership of data, responsibility for integrity, server-driven hypermedia, etc.
For example, when suggesting an edit of a server resource using PUT, the client has
to round-trip the entire representation it received, with all the server’s links, and all
the content that it may not even understand. It drops its own edits somewhere in the
middle and then lets the server sort it all out.
FOREST offers an alternative solution. But since FOREST pushes all the
domain-level interactions up into the content in Functional Observer exchanges
and only uses HTTP for pulling and pushing data, it is not obvious how to
create, update and delete data, or how to manage optimistic locking. These are
all traditionally performed in REST approaches through PUT, DELETE, PATCH,
If-Match/Precondition Failed, etc., in the HTTP layer. What are the equivalents to
these up in the content or domain layer, where FOREST has just state declarations –
which are anyway incompatible with such imperative editing commands?
There is limited space in a single chapter to describe the full interaction here, but
to summarise it: we should agree on a schema or syntax for describing “idempotent
edit intentions” in objects that are then POSTed to a target object to be edited. These
declarative intentions say things like: “I think you are in this state, and I’d like you
to move into this state”, or “this is what state I want you to have, regardless of your
current state”, or “please have this bit of data, that I believe is here currently, appear
over there, instead”. All of these, being idempotent, can be POSTed repeatedly;
those that specify current state are simply ignored if there is no match.
The great advantage of handling data editing up in the domain or content layer is
that that layer has full insight into the nature of the data being edited, and can thus
make intelligent decisions about incoming requests. For example, it may be possible
to merge a “late” edit request instead of rejecting it as out of sync, or perhaps to
partially apply it – if within the integrity constraints and expectations of the domain.
Otherwise, version synchronisation is still dealt with in the content in a similar way
to the “not-as-ordered” flag in the fulfilment example above.
190 D. Cragg
But then again, if you are thinking in such high-level domain terms, are you sure
you want a low-level, direct, data-editing interaction, anyway? Just let the client
express domain-level (rather than syntax-level) declarations and intentions directly!
User Objects
What if a user wanted to play in this object Web? Indeed, suppose that user, quite
reasonably, wanted to use a browser to access it? How does FOREST’s object
resource interaction model work then?
In MVC terms, the raw domain Model objects of FOREST will need some
decoration, some transformation into a View. Serialising them into XHTML would
allow them to be rendered reasonably well in their raw state – then perhaps made
more presentable by including some Javascript and CSS.
If serialised into JSON, they can be rendered to a View by a “FOREST browser”
Web page, which would include some Javascript that knows how to navigate through
and present the object Web, in from a starting point, perhaps detecting common
object types and giving extra relevant interactivity for them.
On the POST side, or the Controller of MVC, the object in the application state
that would be pushed back at the objects being rendered depends on those objects
and their interaction specification.
The centre of any browser-hosted segment of object Web, however, is a first-class
User object. This object can hold the user’s identity, vCard, chat status, etc., any of
which could be POSTed to objects that are interested.
This whole area is far too broad to discuss in any depth in this single chapter, as it
takes us into the rich subjects of Web Applications, Widgets, Ajax, Forms, HTML5,
Mashups, etc. Suffice to say that FOREST is an excellent foundation for all that.
Functional Observer object resources are masters of their own evolution, never told
what to do by other objects in the hyperdata graph. They determine their own state
by looking around. These objects take responsibility themselves to pull and push
state, guided by the domain logic for the class to which they belong.
All the pulling and pushing can happen completely automatically and transpar-
ently – an object just has to focus on meeting its domain rules, and all observed
objects visible through links, or links to links, are fetched when needed; plus, every
time that object updates, its Etag is incremented and its state is pushed out to its
local and some of its remote dependents.
This programming model brings the focus right down to what is important –
an object taking care of meeting its own domain constraints and state evolution
given what it can see of itself and others through its links to them, and letting
7 FOREST: An Interacting Object Web 191
the framework take care of the state transfers in and out needed to support that.
It allows very expressive declarative and reactive programming styles to be used.
As mentioned above, this has affinity to the models available in Clojure and Erlang.
A great advantage of leaving the state transfer up to the framework is that it
can handle not only the cacheing of remote objects, but also making local objects
look much the same as remote ones, apart from the handling of timeouts and
retries. This is most effective with an asynchronous and reactive programming
model. Treating local objects like remote ones eases the further partitioning of an
application. Clearly, it would make sense, in this light, to de-serialise remote object
representations into their “solid” equivalent objects in an object cache.
This declarative programming model also leads quite naturally to the “eventual
consistency” optimisation seen in large-scale systems. Instead of a workflow being
kept in lock-step through an imperative model, we can relax and let the system
“settle when it is ready”. A relative disposition of object states at any time is either
fully resolved, or “in tension” – needing further state evolution to reach the domain
constraints being applied to each object involved.
Functional Observer:
• Implement domain logic as functional dependencies between objects’ state.
• Ensure object structure conforms to common, shared standards.
• An object’s next state depends on its current state plus the observed state of other
linked objects.
• Ensure objects are masters of their own evolution guided by other linked objects.
• Discover these objects through links and links to links.
• Alternatively discover objects via initial incoming push, leading to a new link.
• Implement interactions using the Observer Pattern with observation via pull and
push.
• Guide the pulling and pushing of interdependent objects by domain logic over
object interaction specs.
• Push new state out to all observers and any objects that should be interested
according to the domain logic.
• Ensure an object cannot see the list of its observers.
• Ensure objects only take what they need from their observed objects.
• Use timeouts on pull and push that depend on domain context.
• Consider using or writing a framework that automatically handles the pull and
push of dependencies locally and remotely, automatically setting new Etags and
propagating new state.
• Drive appropriate objects partly or fully by external processes and interfaces.
192 D. Cragg
Hyperdata:
• Expose domain and application state via HTTP as your object resources with ids
mapped to URLs.
• Choose a common, base, data-oriented object serialisation or representation
format from XML, XHTML1/5 or JSON.
• Within that format, ensure your objects conform to standard or pre-existing
schemas where possible.
• Render links between objects as URLs in the serialisation, using links of the
Media Type, if any, or maybe using XLink.
• Thus link up objects within and across applications into a global object Web.
• Separate responsibilities in your applications by partitioning your object space.
• Treat local and cached remote objects the same, to ease ongoing partitioning.
State Transfer:
• Use HTTP statelessly and only as an object representation state transfer protocol.
• Use standard HTTP headers and return codes to drive state transfer only.
• Use GET to pull remote objects on which local objects depend, following links.
• Use POST to push updated object state idempotently to known dependent
objects.
• When POSTing, include the object’s URL in its serialisation or in the POST
headers.
• Use polling, max-age, retries and timeouts on both GET and POST as required.
• Return any new state of the target on a POST response, whether 200 or 303.
• Otherwise, return 204, 403, 405, etc., as required.
• De-serialise remote objects and cache only their object forms.
• Drive optimal cacheing by using HTTP headers correctly; return 304s, etc.
• Use proxies and proxy-caches where beneficial.
Optional:
• Consider using declarative, functional, reactive or other asynchronous program-
ming styles over the Functional Observer framework.
• Consider using eventual consistency where appropriate.
• Consider exploiting cache information on POSTed objects held either in the
object itself or the POST headers.
• Consider, as an optimisation, consolidating cache notification using single
POSTs to a Cache-Notify URL.
• Consider, as an optimisation, asking for cache updates on GETs using Cache-
Notify.
In short: design your application as a graph of objects that interact through the
Functional Observer Pattern: write your application domain logic such that the state
of those objects depends on their current state plus the state of those other objects
they can “see” through links. Transfer that state by either pull or push. Integrate
7 FOREST: An Interacting Object Web 193
or distribute applications by publishing objects into a shared object Web via ids
mapped to URLs and state mapped to a generic Media Type, with inter-object links.
Then map object observation by pull and push to GET and POST respectively.
Conclusion
References
Armstrong J., Williams M., Wikstrom C. and Virding R. Concurrent Programming in Erlang,
Prentice-Hall, Englewood Cliffs, NJ, USA. (1996). Online: http://www.erlang.org
Berners-Lee, T., Fielding, R.T. et al. httpRange-14: What is the Range of the HTTP Dereference
Function? (2010). Online: http://www.w3.org/2001/tag/issues.html#httpRange-14
Berners-Lee, T., Fielding, R.T. et al. Uniform Resource Identifier (URI): Generic Syntax, (2005).
Online: http://www.ietf.org/rfc/rfc3986.txt
Cragg, D. Web Objects Ask, they Never Tell j The REST Dialogues, (2009). Online: http://duncan-
cragg.org/blog/post/web-objects-ask-they-never-tell-rest-dialogues/
Dahl, R. Node.js, (2009). Online: http://nodejs.org/jsconf.pdf
Fielding, R.T. Architectural Styles and the Design of Network-based Software Architectures.
Doctoral dissertation, University of California, Irvine, (2000). Online: http://www.ics.uci.
edu/fielding/pubs/dissertation/top.htm
Fielding, R.T. Post to the REST-Discuss Mailing List, (2006). Online: http://tech.groups.yahoo.
com/group/rest-discuss/message/6613
Fielding, R.T. Economies of Scale, (2008). Online: http://roy.gbiv.com/untangled/2008/economies-
of-scale
Fielding, R.T. et al. HTTP/1.1, Part 3: Message Payload and Content Negotiation, (2011). Online:
http://tools.ietf.org/html/draft-ietf-httpbis-p3-payload-14
Fielding, R.T. et al. Hypertext Transfer Protocol – HTTP/1.1, (1999). Online: http://www.ietf.org/
rfc/rfc2616.txt
Fielding, R.T. et al. HTTP/1.1, Part 2: Message Semantics, (2010). Online: http://tools.ietf.org/wg/
httpbis/draft-ietf-httpbis-p2-semantics/
Hickey, R. Clojure’s Approach to Identity and State, (2009). Online: http://qconlondon.com/dl/
qcon-london-2009/slides/RichHickey PersistentDataStructuresAndManagedReferences.pdf
Mealling, M., Denenberg, R. Report from the Joint W3C/IETF URI Planning Interest Group: Uni-
form Resource Identifiers (URIs), URLs, and Uniform Resource Names (URNs): Clarifications
and Recommendations, (2002). Online: http://www.ietf.org/rfc/rfc3305.txt
Part III
Development Frameworks
Chapter 8
Hypermedia-Driven Framework for Scalable
and Adaptive Application Sharing
Abstract This chapter describes our experiences designing a solution for scalable
and adaptive sharing of desktop and mobile applications, using a lightweight
network-based system compliant with the REST architectural style. The system
delivers consistency of the rendered user interfaces with the state of the application
logic using a stateless networking substrate. We describe the architecture focusing
on how to model the user interfaces as a set of web resources. Then, we present the
prototype that implements the functionality as an extension of the Qt framework,
which works with different Qt-based user interface toolkits. Finally, we present a
multi-display and multi-user Texas Hold’em application that shows how the system
is used in practice.
Introduction
V. Stirbu ()
Nokia Research Center, Visiokatu 1, Tampere 33720, Finland
e-mail: [email protected]
Motivation
Fig. 8.1 Transition from traditional thin computing to an environment where applications can
reside on any device and have the user interfaces rendered remotely according to the local look
and feel
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 201
Fig. 8.2 Usage scenarios: application virtualization (left), and multi-display, multi-user applica-
tions (right)
application screen sharing scenarios in which the use interface is treated as a whole,
enabling innovative applications that have the multiple user interfaces rendered
remotely.
Usage Scenarios
The remote user interface paradigm can be applied in several ways depending
on where the user and the application logic are physically located. From this
perspective we can split the usage scenarios into two categories: pull and push.
In the pull scenario, the user operates the device rendering the user interface, while
in the push scenario the user operates the device where the application logic runs.
These basic interaction primitives can be combined to tailor specific usage needs:
• Application virtualization. The application virtualization describes the situation
in which the applications run on remote devices (e.g. personal computers,
remote servers, consumer electronics or mobile devices) and the user interface
is rendered on the device operated by the user. This scenario resembles closely
the classical thin-client except that the exported user interface uses the local look
and feel of the rendering device.
• Multi-display applications. The multi-display application scenario describes
the situation in which the application runs on the device operated by the user and
additional user interfaces are exported on nearby devices that render them using
the local look and feel. Depending on the application context, these displays can
act as secondary displays for the application or can be operated by additional
users, a situation in which the application running on the remote device appears
to the other users like a distributed cooperative application (Fig. 8.2).
202 V. Stirbu and J. Savolainen
Abstract User Interface Toolkit Specific User Interface Device Specific User Interface
Fig. 8.3 Development process for scalable and adaptive user interfaces
User interface description languages, such as UIML (Helms et al. 2008) and
UsiXML (Limbourg et al. 2005), attempt to describe the user interface in declar-
ative terms, without using low-level computer code. They aim at reducing the
development effort by providing abstractions and automating the design process.
Alternatively, SUPPLE (Gajos and Weld 2004) proposes a mechanism that auto-
matically generates user interfaces according to device constraints. However, in
practice, the challenges of having applications able to export the user interfaces
to any device are significant (Want and Pering 2005). Therefore, we adopt a more
relaxed approach that allows application developers to decide on what methodology
to use for creating the user interfaces, and which devices they target.
This section describes our approach for modeling the user interfaces of desktop and
mobile applications as web resources. We start with an overview of the distributed
system that enables applications to export their user interfaces to remote devices
using the web architecture. Then, we describe in detail the functionality of the
web resources that expose the user interface. Finally, we present the web-based
mechanism that allows the remotely rendered user interface to be consistent with
the state of the application, considering both the static dimension (e.g. user interface
structure, consisting of elements and layouts), and the dynamic dimension (e.g. the
values presented to the users at run-time) of the user interface.
Architecture Overview
S S
Controller View
Model
Application
The user interface resource provides the first interaction point between the user
agent and the application exporting the user interface (Fig. 8.5).
The GET method allows a user agent to acquire a user interface toolkit or
device specific representation of the user interface. The user agent informs the
user interface resource about its capabilities in the request using the User-Agent
header and the HTTP content negotiation mechanism (e.g. the Accept header).
The User-Agent identification string provides hints on the user interface toolkit
version and on what device the user agent runs on, which can be further mapped
to device form factor. The Accept header indicates the format in which the user
agent accepts the representations. Based on the information provided by the user
agent the resource implementation selects the most appropriate user interface, if
any. The response body contains the toolkit or device specific representation of the
user interface. Additionally, the header section contains links to the user interface
element resources, to the event listener resources and to the monitor resource, which
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 205
Structure (Abstract)
name
element
element element
User Interface Resource
element element
Hypermedia relationships
(Link headers)
Behavior:
Rules
Toolkit/Device
Structure (Toolkit/Device) Representation
name
MainWindow
Widget Widget
Label Button
Fig. 8.5 Relations between the abstract user interface, toolkit/device specific user interfaces and
the user interface resource
enables the user agent to be notified when the resource state changes. The URIs
indicating the resources are provided using the Link (Nottingham 2010) header,
and its relation rel to the current document are widex.ui, widex.el, and
monitor (Roach 2010), respectively:
# Request
GET /appui HTTP/1.1
User-Agent: {User agent identification string}
Host: example.org
Accept: application/vnd.com.example.toolkit
# Response
HTTP/1.1 200 OK
Content-Type: application/vnd.com.example.toolkit
Link: </appui/uiHub/{uiElement}>; rel="widex.ui";
uiElements="aUiElement,anotherUiElement,",
</appui/elHub/{eventListener}>; rel="widex.el";
eventListeners="anEventListener,anotherEventListener,",
</monitor>; rel="monitor"
Although the URI scheme that identifies the user interface resources is flat, a
typical toolkit specific representation of the user interface representation contains
all information that allows a client to reconstruct the scene-graph structure. In case
a toolkit specific representation does not have native support for describing the
hierarchy of the user interface, we can overcome this limitation using use the XML
linking language (Xlink) (DeRose et al. 2001) defined mechanism to encode the
relationships between the resources.
The GET method allows a user agent to acquire the runtime values of relevant
properties of the target user interface element. The properties of interest are
indicated as the value of the q parameter of the query. If the query is missing, the
server returns a list with all properties and their values that are considered relevant
for the target user interface element:
# Request
GET /appui/uiHub/{uiElement}?q={paramName} HTTP/1.1
Host: example.org
# Response
HTTP/1.1 200 OK
Content-Type: application/json
Link: </monitor>; rel="monitor"
Link: </appui/uiHub/{uiElement}>; rel="edit"
{"paramName": value, }
If the value of a property has binary representation (e.g. an image), the response
does not contain the value, but includes a JSON encoded link pointing to the content:
{
"paramName":{
"link":{
"href":"/static/144115205255725056.png",
"rel":"widex.static"
}}}
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 207
The POST method allows user agents to update the values of specific properties
of the target user interface element. Typically, the argument of the call is a dictionary
containing key-value pairs:
# Request
POST /appui/uiHub/{uiElement} HTTP/1.1
Host: example.org
{"paramName": value, }
The PUT method allows a user agent to inform the controller that an event
relevant for the target event listener was emitted on the user agent. The Controller is
notified immediately when the message is received and the appropriate event handler
is invoked with the provided parameters. Typically, the message body contains a list
containing the values captured on the user agent by the listener:
# Request
PUT /appui/elHub/{eventListener} HTTP/1.1
Host: example.org
[aValue, anotherValue, ]
208 V. Stirbu and J. Savolainen
Maintaining the state of the user interface synchronized with the application logic
state is essential for an interactive application. In our network-based system, we
use a change propagation mechanism to keep the user interface rendered by the
user agent consistent with the application. The mechanism is driven on the server
side by a special resource that notifies the user agent when representations change,
and on the user agent side by the links embedded in responses from view and
controller related resources. We first describe the monitor resource and then we
describe how the change propagation effect is achieved in a way compliant with the
REST architectural style.
# Response
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
{
"link": {
"href": "/appui/uiHub/aUiElement?q=aParamName",
"rel": "widex.update"
}}
...
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 209
GET/appui
GET/appui/uiHub/uiElement
GET /monitor
Fig. 8.6 Interaction pattern during the initialization of the change propagation mechanism
notification
GET ?q=paramName
Event
User Agent UI Element
Listener
PUT/appui/elHub/eventListener
POST
/appui/uiHub/uiElement
Fig. 8.8 Interaction pattern for user agent initiated change propagation
value on the corresponding resource exposed by the application. Similarly, the user
agent notifies the application when a relevant event occurred by transferring to the
application the event context characterized by the values corresponding to the event
listener signature.
Prototype Implementation
This section describes the prototype implementation that enables scalable and adap-
tive sharing of Qt applications. Our implementation features the core components
providing the server and the user agent functionality, and a set of add-on tools that
speeds the task of creating and inspecting the network behavior of applications. The
programming environment for application developers is Python, the bindings for Qt
framework being provided by either PySide1 or PyQt4.2
1
http://www.pyside.org/.
2
http://www.riverbankcomputing.co.uk/software/pyqt/intro.
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 211
PyWidex
Other
QtGui QtCore QtNetwork QtGui QtCore
Qt Modules
Tornado
PySide Web PySide
Framework
Qt Framework Qt Framework
Fig. 8.9 The core components and their relation to the Qt software stack: application (left), and
user agent (right)
The core components contain the basic functionality that enables scalable and
adaptive sharing of Qt applications. The server functionality is provided by PyWidex
(Widget Description Exchange). The package offers WebBackend, a convenience
class that encapsulates all features needed to expose a view as a set of web resources,
runs in its own thread, and is implemented as a web application running on top
of Tornado,3 a non-blocking, event-driven web server and RESTful framework
optimized for real-time web services. Typically, an instance of this class is a property
of the top level widget that provides the sharable view (Fig. 8.9).
The user agent is a standalone Qt application that is able to render the user
interfaces exported by remote Qt applications, using the user interface toolkit
specific to the rendering device. The user agent implementation is currently able
to render user interfaces using multiple Qt user interface toolkits, e.g. QtGui or
MeeGo Touch Framework. To render the user interface, the user agent application
needs to know only the URI of the user interface resource of the view exported
by the application. Once this information is known, the user agent configures itself
using the information provided in the user interface representation.
Tools
Besides the core components, our prototype provides a set of add-ons that speeds
the process of developing compatible applications:
3
http://www.tornadoweb.org/.
212 V. Stirbu and J. Savolainen
Experimental Evaluation
For any application, each user interface level interaction is typically implemented
by the middleware using several network level interactions. For example, for
initializing the user interface there is at least a request for each user interface
element, which might add up to large numbers depending on how complex the user
interface is. While using the application, each user interface change is implemented
using one or two requests. Therefore, to evaluate the responsiveness of the user
level interaction we need to aggregate the information from individual network
interactions.
Among the views of the Texas Hold’em application, the game table is the
most complex. The view presents information of common interest about the state
of the game: four widgets for each user that plays the game, containing player
specific information, one widget for showing the community cards and a side panel
that provides information about the game phase. In total, the view contains 13
label widgets displaying images of the cards and 21 label widgets displaying text
(Fig. 8.12).
The number of widgets that compose the game table makes this view a good
candidate for determining how much time is needed by an user agent to render the
initial user interface. Also, as the view contains common information about the state
of the game, it gets updated frequently. Therefore, we use it for assessing how much
time is needed to deliver the updates to the user agent.
We performed two round of tests. For the first test we used mobile devices for
both Bob and Alice in an environment that simulates the intended usage scenario.
For the second test we used laptops for all users with the intent of evaluating the
impact of the hardware configurations.
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 215
Fig. 8.13 Game table initialization: application running on N900 (top) and application running on
laptop (bottom)
While the user perceives the initialization of the user agent as one button click away,
at network level the operation is decomposed into 67 requests. The interactions
between the user agent and the application for initializing the game table user
interface are described in Fig. 8.13. The top chart presents the interaction when the
application runs on N900 while the bottom chart shows the interaction when the
application runs on the laptop. Each interaction is broken down in three components
each representing the time needed to process the request in the client, the server,
as well as the delays induced by network propagation and the lower networking
software stack.
The last bar in each chart represents the perceived initialization interaction. As
both the server and the user agent are controlled by an event loop, operations
associated with the requests are executed sequentially. This allows us to compute
the total processing time for the client and server as the sum of individual request
times. Due to HTTP pipelining, we are not able to determine the network induced
216 V. Stirbu and J. Savolainen
Fig. 8.14 Game table updates for a game round: application running on N900 (top), and applica-
tion running on laptop (bottom)
delay, for completing the operation, directly from the information associated with
individual requests. Therefore, we compute the perceived network latency as the
difference between the time needed to complete the operation and the time used by
server and user agent to process the requests.
We evaluated how fast the user interface updates are rendered on the user agent by
having the game played by näive bots that advance to the next phase of the game
after 2 s regardless of the cards in their hands. As for the initialization case, we first
run the application on the N900 and then on the laptop. The user agents are the same
in both test. The interaction pattern for each update is initiated by the application that
notifies the user agent when a user interface element has changed, using the monitor
resource. Then, the user agent request the new representation of the resource.
Figure 8.14 describes the interactions between the user agent and the application
for both test scenarios as timeline and individual request completion time, each
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 217
request being breakdown in time required by client and server to process the update,
and network propagation delay. The beginning of the interaction represents the
betting phase and is characterized by few updates, mostly related to one player at
a time. The final part of the interaction corresponds to the showdown, a phase in
which almost all user interface elements are updated in a very short time interval.
This event resembles the user interface initialization, with the exception that the
user interface structure is known and only the runtime values of the properties of the
user interface elements are requested by the user agent, and the network propagation
delay is longer due to notification delivery.
Discussion
REST is an architectural style. It contains a set of design guidelines, but it does not
impose a specific architecture or a methodology. We follow these, but how RESTful
is the resulting system? The Resource Oriented Architecture (ROA) (Richardson
and Ruby 2007) introduces a practical approach for describing RESTful archi-
tectures through four concepts (e.g. resources, names as URIs, representations,
and links between them), and four properties (e.g. addressability, statelessness,
connectedness, and uniform interface). As the concepts are already covered, we’ll
focus the discussion on the required properties:
• Addressability. Our system exposes a resource for every piece of information
that it serves about a sharable user interface: the structure using the user interface
resource, the data presented to the user as user interface elements resources, and
the behavior as event listener resources.
• Statelessness. Our goal of having the state of the rendered user interface syn-
chronized with the application logic seems to go against statelessness. However,
because the data of a sharable user interface is exposed at network level in
a certain way by the system resources, the application web backend handles
each HTTP request in isolation. All responses are generated based only on the
information contained in the request. Having the networking substrate stateless,
enables simpler generic implementation of the server functionality that can serve
representations to user agents according to their needs.
• Connectedness. Resource representations in our system contain links to other
resources. For example, the representation of the user interface resource has
links to user interface elements and event listener resources, while user interface
element resource may have links to static representations of binary content. These
links point to subresources in the same realm, therefore the system is internally
connected. Specific applications may include in their representations links to
other applications or services.
• Uniform interface. Our resources can be accessed in a uniform way using the
HTTP interface.
218 V. Stirbu and J. Savolainen
Acknowledgements We would like to thank Saku Tiainen for developing the Texas Hold’em
application used for testing, and the referee who provided feedback and suggestions that improved
the content of this manuscript. The research was completed in the Cloud Software Program4 of the
Strategic Centre for Science, Technology and Innovation in the Field of ICT (TIVIT),5 and was
partially funded by the Finnish Funding Agency for Technology and Innovation (TEKES).6
4
http://www.cloudsoftwareprogram.org.
5
http://www.tivit.fi.
6
http://www.tekes.fi.
8 Hypermedia-Driven Framework for Scalable and Adaptive Application Sharing 219
References
Allamaraju, S.: RESTful Web Services Cookbook, pp. 90–91. O’Rilley Media, Sebastopol,
California (2010)
Crockford, D.: The application/json Media Type for JavaScript Object Notation (JSON). RFC
4627, IETF (2006). Http://www.ietf.org/rfc/rfc4627.txt
DeRose, S., Orchard, D., Maler, E.: XML linking language (XLink) version 1.0. W3C recommen-
dation, W3C (2001). Http://www.w3.org/TR/2001/REC-xlink-20010627/
Gajos, K., Weld, D.S.: Supple: automatically generating user interfaces. In: IUI ’04: Proceedings of
the 9th International Conference on Intelligent User Interfaces, pp. 93–100. ACM, New York,
NY, USA (2004)
Hammer-Lahav, E.: The OAuth 1.0 Protocol. RFC 5849 (informational), IETF (2010). Http://www.
ietf.org/rfc/rfc5849.txt
Helms, J., Schaefer, R., Luyten, K., Vanderdonckt, J., Vermeulen, J., Abrams, M.: User interface
markup language (UIML) version 4.0. Committee draft, OASIS (2008). Http://www.oasis-
open.org/committees/download.php/28457/uiml-4.0-cd01.pdf
Khare, R., Taylor, R.N.: Extending the representational state transfer (rest) architectural style for
decentralized systems. In: ICSE ’04: Proceedings of the 26th International Conference on
Software Engineering, pp. 428–437. IEEE Computer Society, Washington, DC, USA (2004)
Krasner, G.E., Pope, S.T.: A cookbook for using the model-view controller user interface paradigm
in smalltalk-80. J. Object Oriented Program. 1(3), 26–49 (1988)
Limbourg, Q., Vanderdonckt, J., Michotte, B., Bouillon, L., Lpez-Jaquero, V.: Usixml: a language
supporting multi-path development of user interfaces. In: R. Bastide, P. Palanque, J. Roth (eds.)
Engineering Human Computer Interaction and Interactive Systems, Lecture Notes in Computer
Science, vol. 3425, pp. 200–220. Springer, Berlin, Heidelberg, New York (2005)
Nottingham, M.: Web Linking. RFC 5988 (proposed standard), IETF (2010). Http://www.ietf.org/
rfc/rfc5988.txt
Richardson, L., Ruby, S.: RESTful Web Services, pp. 79–105. O’Rilley Media, Sebastopol,
California (2007)
Roach, A.: A SIP Event Package for Subscribing to Changes to an HTTP Resource. RFC 5989
(proposed standard), IETF (2010). Http://www.ietf.org/rfc/rfc5989.txt
Stirbu, V.: A restful architecture for adaptive and multi-device application sharing. In: WS-REST
’10: Proceedings of the First International Workshop on RESTful Design, pp. 62–66. ACM,
New York, NY, USA (2010)
Stirbu, V., Leppanen, T.: An open platform for distributed, scalable and adaptive interactive
applications for CE devices. In: The 8th Annual IEEE Consumer Communications and
Networking Conference – Demos (CCNC’2011 – Demos). Las Vegas, NV, USA (2011)
Want, R., Pering, T.: System challenges for ubiquitous & pervasive computing. In: Proceedings of
the 27th International Conference on Software Engineering, ICSE ’05, pp. 9–14. ACM, New
York, NY, USA (2005)
Chapter 9
RESTful Service Development
for Resource-Constrained Environments
Introduction
A. Taherkordi ()
Department of Informatics, University of Oslo, PO Box 1080 Blindern, 0316 Oslo, Norway
e-mail: [email protected]
For years, the use of REST in mobile devices was restricted to client-side interaction
from web browsers. As consequence of Moore’s law, the computing capabilities of
mobile devices are quickly increasing. In particular, we observe that mobile devices
9 RESTful Service Development for Resource-Constrained Environments 223
The Restlet Framework1 is the first RESTful web framework for Java developers
that targets Android for deployment on compatible smartphones. Restlet’s vision
is that the Web is becoming ubiquitous and that REST, as the architecture style
of the Web, helps developers to leverage all HTTP features. In particular, Restlet
on Android supports both client-side and server-side HTTP connectors. However,
Restlet does not include support for the discovery of RESTful services, which is a
fundamental requirement in pervasive environments.
In WSNs, TINYREST is one of the first attempts to integrate WSNs into the
Internet (Luckenbach et al. 2005). It uses the HTTP-based REST architecture to
retrieve/update the state of sensors/actuators. The T INYREST gateway maps a set of
HTTP requests to T INYOS messages in order to link MICA motes (Hill and Culler
2002) to any Internet client. Beside the fact that in TINYREST only a gateway
is able to connect to the Internet (not any individual sensor node), this approach
fails to follow all standard HTTP methods. The work reported in Guinard et al.
(2009) also presents a REST-based gateway to bridge the Web requests to powerful
SUNSPOT nodes.
In this section, we report on a smart home scenario to clarify the motivations of our
work. A smart home generally refers to a house environment equipped with several
types of computing entities, such as sensors, which collect physical information
(temperature, movement detection, noise level, light, etc.), and actuators, which
change the state of the environment. In this scenario, we consider a smart home
equipped with occupancy, smoke detection, and temperature sensors. These tiny de-
vices have the ability to collect context information and to communicate wirelessly
with each other, in order to identify the context situation of the environment. In
addition to that, we can also use actuators to physically control lights, TV, and air
conditioning. Figure 9.1 illustrates the integration of these sensors and actuators
in our scenario. As appreciated in this figure, the different entities use heteroge-
neous protocols to interact. In the scenario, the smartphones provide information
about the user preferences for the home configuration. Conflicts between the user
preferences are resolved by giving priority to the person who arrived first to the
room. The mobile devices also have an application that enables the control of the
actuators present in the different rooms. This application can be adapted when
there are changes in the actuator’s configuration. Finally, there is a Set-Top Box
(STB) which is able to gather information, and interact with the other co-located
devices.
1
Restlet:http://www.restlet.org
9 RESTful Service Development for Resource-Constrained Environments 225
To show how the different elements of our scenario interact, we present three
different situations:
Situation 1: Alice arrives to the living room. The occupancy sensor detects her
presence and triggers the temperature sensors to decrease the sampling rate of data.
It also notifies the STB that the room is occupied by somebody, which in turn tries
to identify the occupant by looking for a profile in her mobile device. When Alice’s
profile is found, the STB loads it and adjusts the temperature and lightening level of
the room according to Alice’s preferences.
Situation 2: The sensors detect smoke and notify the STB, which in turn uses the
occupancy sensor and realizes that the house is empty. The STB therefore sends
an SMS to Alice, including a picture of the room captured using the surveillance
camera. After checking the picture, Alice decides to remotely trigger the sprinklers
using her mobile device. She also tells the system to alert the fire department about
the problem. If Alice does not reply to the STB within 5 min, the system activates
automatically the sprinklers and alerts the fire department.
226 A. Taherkordi et al.
Situation 3: Alice installs a new TV in the bedroom. The STB detects the presence
of the new device, identifies it, and downloads the corresponding control software
from an Internet repository. The platform tries to locate the available mobile devices,
using a discovery protocol, and finds Alice’s mobile device. The STB proposes to
update the mobile device with the components for controlling the new TV.
Key Challenges
The various situations we described above allow us to identify several key chal-
lenges in terms of:
1. Integration of multi-scale entities: The mobile devices and sensors have different
hardware and software capabilities, which make some devices more powerful
than others. Therefore, the integration of these entities requires a flexible and
simple solution that supports multiple interaction mechanisms and considers the
restricted capabilities of some devices. In particular, regarding sensor nodes,
the immaturity of high-level communication protocols, as well as the inherent
resource scarceness, bring two critical challenges to our work: (1) how to connect
sensor nodes to mobile devices and actuators through a standard high-level
communication protocol and (2) the framework which runs over sensor nodes for
supporting context-awareness and adaptation should not impose high resource
demands.
2. Entity mobility: In our scenario, computational entities appear and disappear
constantly. In particular, mobile devices providing user profiles are not always
accessible (they can be turned off or the owner can leave the house with them).
In a similar way, the actuators can be replaced or new ones can be added.
Thus, we need to discover new entities dynamically as well as to support device
disconnections.
3. Information processing and adaptation: In order to support adaptation, we first
need to identify the situations in which the adaptation is required. We have a
lot of information that is generated by the different devices in the environment.
Therefore, we need to define which part of this information is useful to identify
relevant situations and react accordingly. In our scenario, those situations include
the load of Alice’s profile and the adjustment of the temperature, the sending of
an alert via SMS in case of an emergency, and the adaptation of Alice’s mobile
device to control the new TV in her bedroom.
The integration, mobility and adaptation issues impose several requirements for the
development of smart home environments. To deal with these issues, we propose
a comprehensive and simple solution called DIGIH OME, which leverages on the
9 RESTful Service Development for Resource-Constrained Environments 227
SCA Legend:
A B
View
Controller component composite
binding
reference service
The Service Component Architecture (SCA) (Beisiegel et al. 2007) is a set of specifi-
cations for building distributed applications based on Service-Oriented Architecture
(SOA) and Component-Based Software Engineering (CBSE) principles. As illus-
trated in Fig. 9.2, the basic construction blocks of SCA are software components,
which have services (or provided interfaces), references (or required interfaces) and
expose properties. The references and services are connected by means of wires.
SCA specifies a hierarchical component model, which means that components
can be implemented either by primitive language entities or by subcomponents.
In the latter case the components are called composites. SCA is designed to be
independent from programming languages, Interface Definition Languages (IDL),
communication protocols, and non-functional properties. In particular, to support
interaction via different communication protocols, SCA provides the notion of
binding. For SCA references, bindings describe the access mechanism used to
invoke a service. In the case of services, the bindings describe the access mechanism
that clients use to execute the service.
228 A. Taherkordi et al.
Listing 9.1 reflects part of the configuration depicted in Fig. 9.2 using the SCA
assembly language:
provide a simple and flexible mechanism for tracking activities of mobile users
as well as XQuery component implementations, which is not provided by the
standard FRASCATI distribution. Furthermore, the FRASCATI capabilities in terms
of runtime adaptation for applications and the platform itself, make it a suitable
option for customizing the DIGIH OME platform whenever required.
and mobile devices. The CEP Engine is responsible for event processing and uses
the Decision Executor to perform actions specified by the Adaptation Rules
(defined in the CEP Engine). Following a plug-in mechanism, the different Actuator
components grant access to the available actuator services in the environments. This
means that the different actuators are optional, deployed according to the current
service configuration and deployed on different devices.
To enable the communication between different clients and to support the
mobility of services and mobile devices, we also incorporate ubiquitous bindings
in SCA (Romero et al. 2010b). These bindings bring into SCA existing discovery
protocols, such as UPnP (UPnP Forum 2008) and SLP (Guttman et al. 1999),
providing the possibility to establish spontaneous communications. Furthermore,
the ubiquitous bindings improve the context information advertisements with
Quality of Context (QoC) (Krause and Hochstatter 2005) attributes for provider
selection. Once the services are discovered, the ubiquitous bindings are flexible
enough to allow the interaction via standard bindings, such as REST. The use of
these ubiquitous bindings, as well as the modularization of the different concerns,
makes it easy to distribute the different responsibilities in DIGIHOME .
DIGIHOME Resources. A D IGI H OME Resource is an SCA component providing
and/or consuming events to/from other D IGI H OME Resources. In our scenario,
the mobile device executes a D IGI H OME Resource that offers the user preferences
as context information and hosts an adaptive application enabling the control of
home appliances (that also consumes events indirectly in order to be adapted). The
D IGI H OME Kernel can also be considered as a D IGI H OME Resource. Because
our solution is based in standards, and in hiding the service implementation with
SCA, we can easily integrate other services in the smart home that are not part of
the infrastructure (in particular, the actuators). In a similar way, we are exposing the
D IGI H OME Resources via ubiquitous bindings so that other applications (that are
not part of DigiHome) can benefit from the services offered by the platform.
Listing 9.2 reports on the SCA assembly descriptor of the LightActuator
component we developed for interacting with the X10-compliant light appliance
using the REST architectural style (as described in Fig. 9.4):
<composite name="DigiHome.Kernel" xmlns="http://www.osoa.org/xmlns/sca/1.0"> 1
<component name="LightActuator"> 2
<implementation.java class="digihome.LightActuatorImpl"/> 3
<service name="actuator" 4
xmlns:rest="http://frascati.ow2.org/xmlns/rest/1.0"> 5
<rest:interface.wadl description="DigiHome" resource="LightResource"/> 6
<rest:binding.http uri="/light"/> 7
</service> 8
<reference name="light"> 9
<interface.java interface="digihome.ILightActuator"/> 10
<home:binding.x10 xmlns:home="http://frascati.ow2.org/xmlns/home/1.0"/> 11
</reference> 12
</component> 13
</composite> 14
This DIGIHOME Resource is developed in Java (line 3) and exposes the service it
provides as a REST resource (lines 4–8). Technically, we extended the FRASCATI
platform to support the REST architectural style (Fielding 2000). This extension
includes the support for the Web Application Description Language (WADL)
standard (W3C 2009) as a new interface type used to describe the resource
actuator and for the HTTP communication protocol as a new binding type to
access this resource. The REST bindings support multiple context representations
(e.g., XML, JSON, and Java Object Serialization) and communication protocols
(HTTP, XMPP, FTP, etc.). This flexibility allows us to deal with the heterogeneous
context managers and context-aware applications as well as with the different
capabilities of the devices that execute them. Details about the architecture of these
bindings are further presented in Romero et al. (2009).
DIGIHOME CEP Engine. To manage the events in our scenario, we need a
decision-making engine that can process them and create relations to identify special
situations, using predefined rules. In order to identify the desired events, the CEP
Engine requires to communicate with an Event Collector, which is in charge of
dealing with the subscriptions to the event sources. When an adaptation situation
is detected, a corresponding action is triggered, which can go from an instruction
to an actuator, to the adaptation of the system by adding or removing functionality.
These actions are received by the Decision Executor, which has the responsibility
of communicating with the different actuators in the environment.
In DIGIH OME, for the event processing in the set-top box, we use
E SPER (EsperTech 2009), a Java open source stream event processing engine,
to deal with the event management and decision making process. We chose E SPER
for our platform because it is the most supported open source project for CEP and
is very stable, efficient, and fairly easy to use. The following code excerpt shows an
example of an ESPER rule used in our scenario:
select sum(movement) 1
from MovementSensorEvent.win:time(60 sec) 2
In this rule, we can see the use of a time window, which is a moving interval of
time. The rule collects all the events from the movement sensor from the last 60 s.
By doing this, we can know if a user is still in the room or has already left, and adapt
the room accordingly.
DIGIHOME Intermediaries. REST enables Web Intermediaries (WBI) to exploit
the requests exchanged by the participants in the communication process. WBI
are computational entities that are positioned between interacting entities on a
network to tailor, customize, personalize, or enhance data as they flow along the
stream (IBM 2009). Therefore, we can benefit from this opportunity to improve
the performance of DIGIH OME. When the provided context information does not
change much in time, the messages containing this information can be marked
as cacheable within the communication protocol. This kind of annotation enables
WBI caches to quickly analyze and intercept context requests always returning the
232 A. Taherkordi et al.
same document. A similar optimization applies to security issues and the filtering
of context requests. Indeed, by using proxy servers as WBI, we can control the
requested context resources and decide whether the incoming (or outgoing) context
requests need to be propagated to the web server publishing the context resource.
Other kinds of WBI can also be integrated in the system to operate, for example,
resource transcoding, enrichment or encryption.
In order to consume events from WSNs, we use the REMORA Component Frame-
work (Taherkordi et al. 2010). This framework is an extension of SCA that
brings component-based development into WSNs. REMORA proposes a RESTful
mechanism to exchange events, which is encapsulated in an SCA component. We
reuse this mechanism in order to define D IGIH OME resources for WSNs (so called
REMORA RESOURCES), which are able to produce and consume simple objects in
the DIGIHOME platform. With these resources, we improve the efficiency of the
system because the WSN is able to process simple events instead of going through
the DIGIHOME KERNEL for making decisions. The core of our framework enables
in-WSN decisions, whenever an event should be processed with other relevant
events generated by other sensor nodes. As an example, when a temperature sensor
detects a high temperature, to know if there is a fire, it needs to become aware
of the smoke density in the room – i.e., communicating with the smoke detecting
sensors. Furthermore, benefiting from the DIGIH OME modularization of concerns,
as well as the transparent communication promoted by SCA, DIGIHOME objects
can consume/notify events from/to REMORA RESOURCES with a small effort.
This framework presents an IP-based sensor network system where nodes can di-
rectly integrate to modern IT systems through RESTful Web services. This approach
relies on the IP protocol stack implemented in Contiki operating system. Contiki
has made a considerable effort on the provision of IPv4 and IPv6 protocols on the
common types of sensor nodes with constrained resources. Software architecture of
RESThing is shown in Fig. 9.5. It consists of HTTP Server, REST Engine, SAX
9 RESTful Service Development for Resource-Constrained Environments 233
based XML parser and Logger modules. RESThing offers an interface to create
resources since they are the main abstractions of RESTful Web services.
The REMORA runtime is integrated with the REST framework through the
REST Wrapper API. Wrapper API is one of the main features of REMORA,
providing a well-described method for integrating a REMORA application with
underlying system software (Taherkordi et al. 2010). REST Broker contains a set of
REMORA components processing REST requests received from REMORA runtime.
Specifically, it is an intermediate module for handling the REST requests received
from a Web client or sent from the sensor node to a node hosting RESTful Web
services. The broker is also in charge of retaining the list of application-specific
resources and the corresponding REMORA Web services APIs.
HTTP server is a small footprinted server to handle the incoming and outgoing
HTTP requests. It provides interface to perform certain HTTP related tasks such
as accessing request details (headers, entity body and URL path), constructing an
HTTP response, etc. Both REST Engine and SOAP Engine work on top of the
HTTP server. The REST framework also includes a XML parser to parse requests in
XML format. A simple XML parser developed by a third-party (simplexml parser)
is ported to Contiki for this purpose. It is very small in code size and being a
non-validating SAX based parser makes it memory efficient. A minimal SOAP
processing engine is also provided to fulfill SOAP-based Web service invocations.
To do that, it reuses the HTTP server and XML parser components. The engine
parses the SOAP message using the XML parser, extracts the method information
and executes it, finally the response SOAP message is built using the XML parser.
Applications and technologies for the Internet of Things are still in the promotional
phase of design and development. There are numerous hurdles against large-scale
use of the Internet of Things originated from the lack of standards and unmature
business models. We believe that the primary IoT concern in the future will be on the
integration of large-scale enterprise systems with resource-constrained platforms.
The future WSNs and RFID systems, for example, can trigger business processes,
adversely; actions can be triggered on them by a business process being executed on
the Internet. When such platforms are involved in the business process lifecycle, in
addition to today’s communication and distribution issues, several new challenges
arise that are enterprise-specific and difficult to be addressed on resource-limited
platforms, such as workflow management systems. As a result, customizing the
heavyweight enterprise software infrastructures for embedded and resource-poor
systems is envisaged to be a potential research trend of IoT in the future. On
the future horizons of IoT, internet services also serve a key role. The number of
embedded and tiny devices integrated to future IoT will be dramatically increased
so that distributed applications deployed over infrastructures that may encompass
234 A. Taherkordi et al.
tens of thousands of tiny devices, where each device exhibits a high number of
services. Strategies to locate services, as well as devices hosting the services could
be a crucial challenge in the future IoT. It is required to shift the thoughts from
things in the Internet to services, where applications deal with virtual things able
to scale up to the plentiful services over the Internet. These virtual platforms offer
a new higher level of abstraction that hides the low level real things and represent
a different set of things which are characterized as the virtual and new members
of IoT. The way to compose low level real services and expose them in the virtual
things level could be a challenging area in the future IoT.
Conclusion
In this chapter, we have presented DIGIH OME, a platform addressing the mobility,
heterogeneity, and adaptation of smart entities. In particular, DIGIHOME detects
adaptation situations by integrating context information using an SCA-based ar-
chitecture. This architecture promotes the modularization of concerns and fosters
the application of the REST principles by exploiting the SCA extensibility. The
simplicity and data orientation of REST, combined with the SCA independence of
implementation technologies, make DIGIH OME an attractive solution to deal with
heterogeneity in terms of interactions. The definition and application of ubiquitous
bindings in the platform enable spontaneous communication by means of standard
protocols (e.g., UPnP and SLP), and furnish context provider selection (based on
QoC attributes). On the other hand, the modularized architecture of DIGIH OME
allows the definition of variants for the platform, called D IGIHOME resources,
that can be deployed on resource-constrained devices. The functionality of these
resources is exposed as services, accessible via several protocols, which can be
accessed by clients that do not have to be part of the platform. Furthermore, the clear
separation of concerns in the DIGIH OME architecture encourages the exploitation
of WSNs for simple processing and local decision making. The suitability of our
platform for context integration was evaluated with different discovery and context
representations.
References
Introduction
OpenLayers) but, on the other hand, retains all important functionality when one or
more such client features are unavailable? More specifically, how do we combine
the benefits of the REST approach to Web application design with those of active
client-side features such as JavaScript and techniques such as Ajax (Asynchronous
JavaScript and XML) (Garrett 2005)?
To reach a wide audience, a Web application must be able to support a wide
range of client capabilities. Some mobile clients and clients on older computers
often cannot use the latest Web technologies such as Adobe Flash, scalable vector
graphics (SVG) (Jackson and Northway 2005), Java applets, or even advanced
JavaScript. In order to develop an application that is accessible to the largest
audience, developers often design for a simple set of capabilities and eschew the
newer technologies. Alternatively, developers utilize new technologies and provide
an alternative, reduced-functionality version for clients that cannot support the
chosen technologies. And very often, unfortunately, Web applications will simply
display a requirements message to the reduced-capability clients and provide no
functionality at all. The RFDE framework provides a much more attractive option,
as it permits the use of modern JavaScript and other features while retaining
usability on clients without these features, and permits the Web programmer to
support all such clients without explicitly writing code to handle the many cases. In
an RFDE Web application, requests from a client returns a version of the application
that is best matched to that client’s supported, and active, features. The RFDE frame-
work also endows an application with the ability to automatically upgrade itself
using JavaScript and Dynamic HTML (DHTML) to a representation that can take
advantage of more dynamic and advanced client features when they are available.
In the remainder of this chapter, we will describe the Climate Data Explorer, a
climatological web application that inspired the RFDE framework, and identify the
types of applications that can benefit from this approach. We will then introduce
widgets and application templates, which are the building blocks of an RFDE
application, and describe how they can be designed to target a large number of client
environments with varying capabilities. Next, we will describe how we represent
and maintain the state of a dynamic and event-driven application that is implemented
using a RESTful, stateless application server. Finally, we will describe some of the
work related to the RFDE framework, summarize the approach, and describe some
possible future enhancements.
Fig. 10.1 A screen-shot of the Climate Data Explorer (CDX) application, which provides an
integrated and interactive view of a large and diverse collection of datasets. CDX combines REST
and modern dynamic client features using the RFDE framework
Various government and other organizations routinely publish data with direct
relevance to climate. Examples of such organizations in the U.S. include the
Environmental Protection Agency, the National Oceanic and Atmospheric Adminis-
tration, and various state agencies such as the Maine Department of Environmental
Protection. Data from these organizations differs in format and encoding, spatial
and temporal coverage, measured or modeled attributes, and several other char-
acteristics. As a result, it is difficult even for specialists to effectively use this
data, even though most of it is publicly available on the Web. For example, a
record of the global temperature and humidity fields for, say, December 31, 1984
is conceptually trivial to obtain based on datasets available on the Web. However,
actually generating a suitable map-based representation of these fields is a difficult,
laborious, and time-consuming (several hours) task for a specialist, and completely
unworkable for a nonspecialist. In CDX, this representation may be generated in a
matter of seconds using only a few mouse clicks and with no need for specialized
knowledge.
Figure 10.1 depicts a screen-shot of the CDX Web application, illustrating its
use for exploring climate data on a world map. For clients that support the required
capability (mainly, modern JavaScript), the map uses common map features such as
the ability to click and drag the map in order to pan around the globe, and balloon
windows providing instantaneous feedback with more information on a clicked
feature.
Some of the other components used by the CDX application include a historical
graph and a level indicator. At the broadest level of client compatibility, these
controls are both implemented using static images with hyperlinks to new windows
240 E. Albert and S.S. Chawathe
Target Applications
We outline some characteristics of the applications that are best suited to the RFDE
framework, using the CDX application of “Motivating Case Study: A Climate
Data Explorer” as a typical and concrete example. The target Web applications for
RFDE are essentially those for which the three requirements of, briefly, portability,
interactivity, and scalability are of primary importance. These requirements are
elaborated below.
The portability requirement refers to the ability to run on numerous and diverse
computing environments, including various combinations of hardware (desktop
computers, smart phones, kiosks, and more), operating systems, and Web browsers.
For our CDX example, this requirement is crucial in ensuring that the benefits
of exploring climate data are available to as many people as possible, including
those using older hardware and software, and those with special accessibility needs.
A similar comment also applies to, say, a Web store that would like to attract as
large a customer base as possible.
The interactivity requirement refers to the need to have a strong visual impact
and maintain user interest, based on a dynamic interface design that includes
familiar modern Web widgets and provides instant feedback to user actions.
Examples of these widgets include ones for browsing tiled maps, updating lists
and selections based on user actions, and displaying pop-up windows with hints
and error messages. Also included are widgets designed primarily to provide a
visually pleasing experience, such as those for providing smooth transitions between
images, and fade-in and -out of displayed items. While it may be tempting to
10 A REST Framework for Dynamic Client Environments 241
write off the latter as frivolous decorations, their presence often makes a significant
difference to the overall success and user acceptance of the application. For the
CDX application, for instance, retaining user interest to encourage progressively
more detailed exploration of the datasets and the underlying scientific and societal
issues is greatly aided by such widgets.
The scalability requirement refers to the ability to easily increase the number of
concurrent users supported by an application over several orders of magnitudes.
For the CDX application, it is important that the implementation scale easily
from hundreds to several tens of thousands of users as interest in the application
grows and, further, that this scalability be achieved in a predictable manner by
incorporating more hardware resources but without any significant qualitative
change in the core design.
The portability and scalability requirements argue for the use of well documented
and widely implemented Web standards. In particular, the REST approach is very
natural and attractive design choice. The interactivity requirement argues for the use
of modern Web widgets, tools, and JavaScript libraries that take advantage of recent
developments in various parts of the client computing environment. Unfortunately,
these two design choices are, without further work, largely incompatible. The core
REST design and its typical implementations are based on the early interaction
model between Web clients and servers, where most client actions generate a round-
trip to the server, with concomitant implications for response times. Further, it is
not immediately clear how one may apply the REST design to a Web application
in which many actions, and state changes, occur through mechanisms such as
Ajax (Asynchronous JavaScript and XML). This apparent incompatibility and its
resolution are the core topics addressed by the RFDE framework, and this chapter.
While the RFDE approach itself is not dependent on any specific programming
languages, scripting libraries, or client technologies, our implementation of the
RFDE framework built to support the CDX application uses a number of specific
languages that we will use in the examples throughout this chapter. Server-side
code is written in the Java programming language, and client-side libraries and
dynamically generated scripts are written in the JavaScript scripting language.
Widgets
The fundamental resource (in REST terminology) used by RFDE is the widget,
which is a reusable user-interface element that allows one to view and manipulate
application data. Common Web application widgets include form-entry fields,
buttons, pull-down menus, checkboxes, radio buttons, and images. Widgets can also
be built using other widgets, allowing for more complicated interface elements to be
created quickly from the existing library, while also reducing proliferation of very
similar code. By building a large collection of widgets, both general purpose and
application specific, we can quickly create new Web applications that are portable,
interactive, and scalable.
242 E. Albert and S.S. Chawathe
Fig. 10.2 A screen-shot depicting the use of the mapview application template in the CDX
application
The CDX application (Motivating Case Study: A Climate Data Explorer) uses
several application-specific widgets that allow the user to view and manipulate
data from a multi-terabyte climate database. The screen-shot in Fig. 10.2 shows
a simpler version of the climate-data browsing interface that consists of three
primary widgets. The central widget is a map widget that supports the display of
geographical distribution of the concentration of a climate parameter, such as the
pollutant lead or stratospheric ozone. To the left of the map is a navigation control
widget, consisting of several button widgets, that enables the user to pan and zoom
the map. The third widget, displayed as the list of climate parameters to the right
of the map, is a selectable-list widget that permits the selection of a parameter to
display on the map.
A widget is implemented using one or more representations (e.g., a static
image, DHTML, Flash, etc.) that correspond to the capability set (Client Capability
Tiers) of the client. In the CDX application, the map widget is represented using
the OpenLayers JavaScript library when the client supports it; otherwise, it is
represented using a static image rendered on the server-side. Likewise, the map
navigation buttons and the climate variable list items are represented using HTML
anchor tags when JavaScript is not available, and as JavaScript supported clickable
markup when it is.
Widgets can perform tasks through invokable methods and registered event han-
dlers. The map widget is implemented using several methods such as moveNorth,
moveSouth, moveEast, and moveWest which pan the map in the given
direction; center, which centers the map on a given latitude and longitude; and
methods to control the zoom level such as zoomIn, zoomOut, and zoomWorld.
Each of these methods have dual implementations in the CDX library: one in Java
10 A REST Framework for Dynamic Client Environments 243
that implements the method on the server, and one in JavaScript that can be invoked
directly on the client when the widget is represented using the OpenLayers library
(in general, each additional tier would require another implementation of the widget
class). In addition to its methods, a widget can also identify a set of events that it
generates. An event typically corresponds to a user action, such as changing the
zoom level of the map widget (an onZoom event), and an application can specify
what actions are performed when a given event occurs. Further details on methods
and event handling, including examples, appear in “Event Handling”.
The RFDE server publishes a common widget interface that can be used to obtain
the value of a specific widget (that has a derived value) given a set of parameters.
The value of the widget is represented using a language that is appropriate for
programmatic use, such as such as XML or JavaScript Object Notation (JSON)
(Crockford 2006). Later, we will discuss how this interface is used to implement
much of the application dynamically, on the client side, when this feature is
supported by the client environment.
Application Templates
template.addStyleSheet("cdx"); 2
3
MapWidget map = 4
7
List plist = new List(); 8
plist.onChange().addAction( 14
new StateChangeAction( 15
map, "parameter", plist, "selectedValue")); 16
17
template.addWidget(new HorizontalPanel(nav, map, plist)); 18
template.init(); 19
static markup that will be used in every document generated by the template; the
creation of an explicit representation of the default state of the template, based on
the parameters specified in the template definition (Representation of Application
State); and the use of a widget dependency graph to create a valid ordering for
instantiation in client-side code.
When a new template request is made, the server program that hosts the
application is responsible for translating the encoded application state into a state
object, “executing” the template, and returning the resulting document. Executing a
template requires generating the markup language for each of the widgets based on
the current state of the application, as well as creating initialization parameters for
client-side versions of the widget implementation classes. The resulting document
contains static references to external resources used by the document (such as style
sheets), references to the RFDE libraries that implement the client-side versions of
the widget classes used by the template, the generated upgrade parameters and event
handlers, and finally, the markup the implements the page and its widgets (example
markup for an image push button widget is given on page 247).
The RFDE framework supports the development and deployment of Web appli-
cations that support, concurrently and interchangeably, client environments with
diverse and changing capabilities. For instance, one user may run the application on
10 A REST Framework for Dynamic Client Environments 245
Client Server
Widget Request
Tier n Representation Widget Value
Widget Interface
Widget Request
Tier 2 Representation
DHTML and JavaScript Widget Value
Upgrade /
Downgrade
Template Request
Tier 1 Representation Application
Static HTML and Images Template Document Template Interface
a desktop computer running Windows XP and Internet Explorer 8 while others (or
the same user) access it using, variously, a smart phone running Symbian and Opera,
a kiosk running GNU/Linux and a customized version of Firefox, or a computer with
software that is several years behind the current versions.
It would be foolhardy to attempt to explicitly address every possible combination
of the components of a client environment: hardware, operating system, Web
browser, and so on. Instead, RFDE models the features and abilities of the comput-
ing environment on the client side using client capability tiers. These tiers classify
client environments by specifying the properties required for tier membership.
RFDE includes a default definition of these tiers, but application programmers may
easily modify both the number of tiers and the individual tier definitions, and such
modification is expected and encouraged. The lowest tier (Tier 1) is designed to be
as inclusive as possible, and thus specifies the bare minimum for what is needed
for the application to function. A guideline for Tier 1 is to include only those
requirements without which there is no reasonable way to accomplish the key tasks
of the application. As suggested by Fig. 10.3, each higher tier adds increasingly
demanding requirements for the client environment. When a client interacts with an
RFDE application, the framework automatically uses the highest (most capable) tier
that the client’s environment supports. This default behavior may be changed, and
the tier may be explicitly set to a desired one by using tier selection widgets which
are typically used during testing.
Tier 1 clients that support only the minimum requirements are able to use a fully-
functional version of the Web application, although some of the visual and usability
enhancements afforded by more capable environments may be missing. As a simple
example, a client without scripting support may not provide immediate feedback
on potentially incorrect data. However, not only are the functions implemented by
246 E. Albert and S.S. Chawathe
the form (perhaps a purchase) fully supported, but also the feedback on incorrect
data is provided, albeit with a slightly longer response time due to a server round-
trip and page refresh. If the client environment supports additional capabilities,
the application widgets will be automatically upgraded to versions that use these
capabilities to improve the speed, responsiveness, usability, or appearance of the
application. A special JavaScript class in the client-side RFDE library, called the
widget manager, is responsible for the instantiation and automatic upgrade of all of
the widgets in an application document based on the identified tier level of the client
environment.
For the CDX application, consider the mapview template of Fig. 10.2. In Tier 1,
the user is able to pan and zoom the map but must do so using the navigation buttons
on the left. A more direct manipulation of the map by clicking and dragging on the
map itself is not supported because the client environment capabilities (JavaScript,
etc.) that are needed to implement such manipulation are not part of Tier 1. Map
manipulations, and most other actions, in this tier also require full page refreshes
and a new rendering of the visible area of the map, with the associated, typically
noticeable, delays. In Tier 2, the map is more interactive. In addition to the direct
manipulation using dragging, it also permits zooming in and out using scroll wheels
and similar input modes. Further, map features are associated with pop-up balloon
windows with hints or other brief messages. Map tiles and other images are loaded
asynchronously and partial updates of the displayed Web page are accomplished by
manipulating the DOM tree; these enhancements avoid full page refreshes in most
cases and so greatly improve responsiveness.
Figure 10.3 depicts this tiered approach of a RFDE Web application. At the
lowest level of the figure, a client communicates with the application server to
request an updated view of the application. At this level, the document returned
contains the entire application template, including all the widgets in the template.
The state of the application is explicitly encoded in the URI that the client sends, and
the application view that is returned is represented using a markup language such
as HTML. The hyperlinks in the document contain URIs that encode new states for
the application, so that when the user clicks on a link, the net effect is that the state
of the application is updated and the new view of the data is returned.
Embedded in a Tier 1 client document is a small script that checks client
capabilities when the document is loaded. If the client does not support the scripting
code, it will simply be ignored and the client will remain at this tier for the duration
of the exchange. If the capability check determines that the browser supports
a higher tier, the client-side widget manager will automatically upgrade all the
widgets on the page to their higher-tier representations. For example, Tier 1 may
represent the application using HTML and static images, Tier 2 may add JavaScript
and client-rendered images, and a third tier may use Adobe Flash or advanced SVG
graphics to render the application. If the client supports JavaScript, but not Flash or
advanced SVG, the client code will upgrade the widgets to their Tier 2 versions and
future interactions with the server will take place at the RFDE widget interface.
In addition to the server-side Tier 1 widget library, an RFDE server supports
an arbitrary number of additional levels of higher-capability, client-side widget
10 A REST Framework for Dynamic Client Environments 247
libraries. At these higher tiers, the client requests the value of individual widgets,
instead of entire application templates, through the common widget interface. This
design allows the client to use asynchronous transactions to replace the value
for individual widgets in a template, improving the application’s responsiveness.
The upper-tier widget libraries use representations for widget values that are more
appropriate than HTML, such as JSON, allowing for any type of client technology
(such as HTML, DHTML, SVG, Flash, etc.) to be used to render the widget.
The initial framework developed for the CDX application consists of two tiers
of client capability. However, additional tiers are likely to be added based on
the expected mix of client categories and an important aspect of RFDE is that
such additions can be made easily, without affecting existing code and application
functionality. In the lowest tier, the widgets are represented using HTML 3.2, static
images, image maps, and hyperlinks. The application also uses cascading style
sheets to control the look and feel of the page. These style sheets are ignored by
browsers that do not support them. Images, such as the tiles in the visible area of the
map, are rendered by the server and sent to the client in a widely supported format
such as JPEG, GIF, or PNG. In this level, each user interaction with the application
(informally, each click) requires a complete page refresh. For example, a single-
button widget, such as the zoom-in button in the map navigation control widget, is
represented using the following HTML:
<a id="ImagePushButton5"
class="ImagePushButton ImagePushButton-t1"
href="/cdx/1.0/mapview?state=&e5=zoomIn">
<img src="/images/map/zoom-in.jpg"
alt="Zoom In"
border="0" />
</a>
The widget is represented as a simple hyperlinked image in this tier. When the
user clicks on the image, indicating a zoom-in event, the state of the application
is updated (in a REST-compatible manner) following a round-trip interaction with
the application server and subsequent page refresh at the client. Event handling is
discussed further in “Event Handling”.
If the client supports JavaScript, DHTML, Ajax, and SVG, it is automatically
promoted to second tier functionality when the application is loaded. In this tier,
each upgradeable widget is replaced with its JavaScript and DHTML implemen-
tation. After such an upgrade, client interactions no longer require a full page
refresh. Widgets change their displayed forms by using client technologies, such as
JavaScript and DHTML. For example, the upgrade dynamically replaces the earlier
static-HTML representation of the zoom-in button with its second tier equivalent:
<img id="ImagePushButton5"
alt="Zoom In"
src="/images/map/zoom-in.jpg"
class="ImagePushButton ImagePushButton-t2">
Unlike the earlier representation, there is no longer a static hyperlink and the
widget identifier now appears in the image tag. The ImagePushButton-t1
CSS class has been replaced with the ImagePushButton-t2 class, allowing
248 E. Albert and S.S. Chawathe
Map1
Latitude: 48.4070
Map1 List1
Zoom: 6 Selected: 3
Map1 List1
Latitude: 40.7166 Selected: 0
Longitude: −74.0067
Zoom: 1
Width: 400
Height: 300
Parameter: o3
Fig. 10.4 An example of the representation of an application template’s state. The innermost state
represents the application’s default state while the outer states are specific to a client request
application state is shown in the innermost layer of the diagram, which contains
values for all of the properties for the two widgets. The order of the properties in the
diagram corresponds to the order of the values in the state value string, so latitude
is the first, longitude is the second, and so on. When the client does not specify a
value for the application state, the default state is used (1.0 identifies the version of
the web application):
/cdx/1.0/mapview
A client may also use the following complete state representation, even when the
application is at its default state.
/cdx/1.0/mapview?state=Map1:40.7166:-74.0067:1:400:300:o3*List1:0
A working state is a representation of state that keeps track of changes from another
state (typically the default state, but working states may also be nested). When the
client sends a request for an application template, the server builds the working state
for the request which is then used to generate the document that is returned. If a state
variable is not included in a working state, the default value for the variable is used.
The middle layer in Fig. 10.4 represents the current client state, in which the values
of two state variables have been changed from their defaults. This state is created in
response to a client request with the following application URI:
/cdx/1.0/mapview?state=Map1:::6*List1:3
250 E. Albert and S.S. Chawathe
The only changed property of the map widget is the zoom level, which is the
third property of the widget. The colons corresponding to the first two properties
of the map widget must be included in the encoding to ensure proper positional
representation; however, additional colons at the end of an encoding may be
dropped. In this example, the colons corresponding to the last three properties
(width, height, and parameter) are dropped because these properties retain their
default values.
The outermost working state in Fig. 10.4 represents a potential future state that
may be used to generate proper URIs for inclusion in the current application
hypertext. In this example, this future state represents the state of the application
if the user were to pan the map to the north, and this state could be encoded in the
hyperlink URI for the corresponding map control button:
/cdx/1.0/mapview?state=Map1:48.4070::6*List1:3
The default state representation for an application template is a constant value that is
only initialized once, when the template is created, and then shared among all client
requests. When the server receives a new request, it only has to instantiate a more
light-weight working state to represent the changes from the default state. When a
working state is created, the RFDE application server automatically performs type
and sanity checking of the state values based on constraints that can be specified
when a widget registers a new state variable in the default state.
While operating at the lowest tier level, the client manages the application
state implicitly, using state-encoded URIs in hyperlinks and HTML forms. When
a client is upgraded to a higher tier level; however, the client becomes more actively
responsible for keeping track of the state of the application. Many of the actions
that are performed by an event handler are simple to complete on the client, such as
changing the CSS classes used by the selectable-list widget in order to highlight a
newly selected value, and requiring a round-trip exchange with the server in order
to perform this task would be an unnecessary cause of latency that would affect the
perceived responsiveness of the application.
The widget manager is responsible for keeping track of the application state on
the client. While the server needs to explicitly model the default state and any
changes to the default state made by each of the clients, the client only needs to
keep track of the current state of the application. When the application state is
changed, the widget manager requests any updated widget values from the server
(if necessary) and updates the current application URI to allow the user to bookmark
any particular view of the application.
Event Handling
We use the term events to refer to the interactions of a Web application user with
the user interface. Examples of events include clicking on buttons, selecting items
in drop-down menus, and panning a map. Each application widget recognizes the
10 A REST Framework for Dynamic Client Environments 251
events that relate to it. For example, a map may have an onMove event which
corresponds to a user request for panning to a new location and an onZoom event
which corresponds to a user request for changing the zoom level. Each event may be
associated with a set of actions that are performed whenever the event occurs, and
these actions may in turn affect other widgets in the application. A simple example
in the CDX mapview template is that changing the selected climate parameter in
the list widget also changes the parameter that is displayed in the map.
After creating the widgets in an application template, the programmer specifies
the application behavior by associating actions with widget events. Actions can
affect an application in various ways, such as changing a state variable, invoking a
widget’s method, or even firing another event, which may in turn trigger additional
actions, recursively. For example, the zoom-out button in the navigation widget of
the CDX application is assigned an action that invokes the map’s zoomOut method
when the user clicks on the button:
zoomOutButton.onClick().addAction(
new InvokeMethodAction(map, "zoomOut")
);
The manner in which this event handler is executed depends on the client capability
tier (Client Capability Tiers) that is active at the time of the event.
In Tier 1, an event is initiated by including an event identifier in a request query
string. Events have an optional argument which is used to specify event parameters.
For example, an event caused by the user selecting a different climate variable
would be parameterized with the index of the new selection. When there is no actual
parameter, the value 1 is used to indicate that the event was activated. In the CDX
application, the zoom-out button’s onClick event is assigned the identifier e3 and
the hyperlink has the following URI:
/cdx/1.0/mapview?state=List1:2&e3=1
This URI indicates that the only change from the default state of the mapview
template is that the third climate parameter is selected in List1 (using zero-based
indexing) and that the zoom-out button has been pushed.
When the server receives a request that includes an event identifier, it immedi-
ately triggers the associated event handler. In this case, the only associated action is
to execute the zoomOut method of the map widget, as specified by the following
server-side code fragment:
public void zoomOut(WorkingState state, String param) {
int zoom = state.getIntegerValue(getId(), "zoom");
onZoom().fireEvent(state, "out");
}
Since templates are stateless, the current application state is passed as the argument
state to the zoomOut method. The method determines the current value of the
252 E. Albert and S.S. Chawathe
zoom, updates it, and modifies the working state. Finally, the method triggers the
map widget’s onZoom event which, by similar mechanisms, triggers the appropriate
event-handling method for the map widget, which will cause any actions identified
as side-effects to changing the zoom level to be also be executed (there are none in
the mapview example template).
Once the server has completed executing all of the event handlers, the client is
immediately redirected, using an HTTP 303 See Other redirect, to a URI that fully
encodes the new application state based on the updated value of the working state.
Thus, the non-transient URIs at the client never include pending events. As a result
of the zoom-out widget’s onClick event, the client is redirected to the following
URI with a modified zoom value:
/cdx/1.0/mapview?state=Map1:::0&List1:1
At higher tier levels, more of the event handling is managed on the client side
in order to increase the responsiveness of the application and to reduce the number
of complete page refreshes. Tier 2 event handling in RFDE is performed by the
JavaScript implementations of the widgets. When widgets are initialized, they are
given JavaScript versions of event handlers. The zoom-out button is instantiated
with the following event handler, which is automatically generated from the Java
version of the event handler (the $I function returns the instance of the identified
widget):
onClick: function(param) {
$I(’Map1’).zoomOut(param);
}
The client-side JavaScript version of the map widget has the following implementa-
tion of the zoomOut method:
zoomOut: function(param) {
this.onZoom("out");
}
This client-side implementation of zoomOut is nearly identical to the earlier
server-side implementation, but there are two notable differences: First, the widget
manages its own state directly rather than requiring the state as an additional
argument. Second, and more important, the client-side version of the method
actually causes the map to zoom out as a direct side-effect. Recall that the server-
side version only modifies the representation of the application state.
When a widget needs to update its value due to an event that is handled on the
client side, it requests the value from the RFDE server’s widget interface, based on
its updated parameters. For example, one of the widgets in the CDX application is a
level indicator, a widget that graphically presents the value and health implications
of a specified climate parameter, such as a pollutant, at a location and time which
10 A REST Framework for Dynamic Client Environments 253
?
Stratospheric Ozone
Level: 293.68 PPB
Fig. 10.5 An example of the level indicator widget which, when upgraded, uses asynchronous
calls to the server to modify its value as a user changes the selected location or date being displayed
are specified using other widgets. Figure 10.5 depicts an example level indicator
for stratospheric ozone (the ozone layer). The horizontal bar in the figure is filled
to indicate the comparative value of the underlying parameter. The bar’s color is
mapped to health standards, with green denoting a healthy level, for instance. In our
Tier 1 implementation of the level indicator widget, it is rendered as a static image
generated on the server side. When the client is upgraded to Tier 2, the indicator is
rendered on the client side and gains niceties such as animated filling of the bar and
a textual description of the level that appears as a balloon activated by a pointer-
hovering event.
When the user changes the selected date or location, the level indicator must
be updated to display the parameter value at the date or location. The widget
sends an asynchronous request for the new value to the widget library. This REST-
based interface can supply the value of a widget based on the widget’s parameters,
in a representation that is more appropriate for programmatic manipulation. For
example, the following URI requests an updated value for a level indicator widget:
/w/1.0/LevelIndicator?state=o3strat:48.41:-74.01:2010-09-23
The server responds with a representation of that value, in this case encoded using
JSON:
{
"widget" : "LevelIndicator",
"version" : 1.0,
"state" : { "parameter" : "o3strat" ,
"latitude" : 48.41,
"longitude" : -74.01,
"date" : "2010-09-23" },
"uri" : "/w/1.0/LevelIndicator?state=
o3strat:48.41:-74.01:2010-09-23",
"param_name" : "Stratospheric Ozone",
"param_alt" : "The Ozone Layer",
"units" : "PPB",
"level" : 293.68,
"US_limit" : undefined,
"EU_limit" : undefined,
"health_idx" : 0
}
On receiving this response from the server, the client-side widget code changes its
internally stored value and re-animates the filling of the display bar.
254 E. Albert and S.S. Chawathe
We now illustrate some of the interactions outlined in earlier sections in the context
of a simple session of user interactions with the CDX application of “Motivating
Case Study: A Climate Data Explorer.” First, the client loads the CDX portal, which
is a directory for a number of CDX application templates, by sending a request to the
server. Next, the user selects a link to the mapview application template. Finally,
the user performs two events on this application page: (1) changing the selected
parameter in the list to lead and (2) activating the zoom out control for the map.
Figure 10.6 illustrates this sequence of events for both Tier 1 and Tier 2
compatible clients. For simplicity, this figure focuses entirely on the interactions
that represent the main application logic flow; not shown are the additional requests
for document resources, such as embedded images, made by the client. The Tier
1 interactions are shown in Fig. 10.6 (a). The first two user requests (for the CDX
portal and the mapview template) are made as standard HTTP GET requests; each
results in the server generating and returning a complete Tier 1 document. The event
a b
User Client Server User Client Server
Hyperlink upgrade
Request
mapview Template
Hyperlink Request
Tier 1 Document
mapview Template
Tier 1 Document
User Event Request
Select Lead
State Redirect upgrade
Request
User Event
Tier 1 Document Select Lead
event handler
Tier 1 Tier 2
Fig. 10.6 An simple CDX session. At Tier 1, each request and event requires a full-page refresh.
Event handlers on the server compute the modified state representation and redirect the client to
the new URI. At Tier 2, event handling is performed on the client and only the values of individual
widgets are requested from the server and updated on the client side. Some events may be handled
completely on the client and do not require a request to the server (such as the onZoom event
corresponding to the user zooming out the map in this example)
10 A REST Framework for Dynamic Client Environments 255
requests (selecting lead and zooming out) require server-side event handling. For
both of these requests, the server receives the request from the client which includes
the event identifier, executes the event handler which computes the new application
state, and then redirects the client to the new application URI, which encodes the
new state.
The corresponding sequence of events for a Tier 2 client is shown in Fig. 10.6 (b).
For complete template requests, the Tier 2 interactions are handled exactly as in
Tier 1; however, when the client loads a Tier 1 document, the embedded script
upgrades the document to its Tier 2 equivalent. In Tier 2, event handling is
performed on the client side, rather than requiring a complete page refresh, reducing
latency and allowing the application a much greater level of responsiveness. When
the user changes the parameter to lead, the event handler for the selectable list
widget’s onChange event (in client-side code) signals the widget manager to
asynchronously request a new value for the map widget. The response from the
widget interface, which is significantly smaller than a complete Tier 1 document,
includes details that the map widget requires to properly render the new map and
to request a new set of map tiles. Some events, such as when the user zooms the
map out, can be handled completely on the client, and do not even require a request
for an updated widget value. The underlying map tiles are requested from the server
as usual, although they may also be cached on the client side by the usual browser
mechanisms.
UIML (Edwards et al. 2000; Ali and Abrams 2001), and use an application-
independent user interface library to realize the application on the host device.
Nokia has described a Remote MVC (model-view-controller) application con-
troller (Stirbu 2010) that models user interfaces as REST resources and that uses
an event-based system to keep the client and service synchronized. When this
framework is initialized, applications can discover and acquire platform-specific
representations of the user interface elements that use a device’s native functionality
and match the look-and-feel of the device.
A significant advantage of the RFDE framework of this chapter is that it allows
the development of portable, interactive, and scalable applications. Rather than
attempt to support the myriad of client devices natively, RFDE models common
client features in tiers of capability. These tiers allow the development of specific
representations for interface elements based on a small number of tiers that
framework implementations support, rather than developing a representation for
each possible device.
While our description in this chapter uses several specific technologies such
as JavaScript and Java, the RFDE design does not depend in any significant
manner on these technologies, and others may be substituted where appropriate.
The framework also does not impose an architectural style (such as MVC) on an
application, and the programmer may choose the one best suited to a task.
Application programmers who use RFDE can develop an application by adding
widgets to an application template and then specifying actions that should occur
as a result of their related events. This development approach is similar to appli-
cation development for desktop applications and Web development frameworks
that are modeled on desktop application development, such as the Google Web
Toolkit (McFall and Cusack 2009). In this approach, the application programmer
may treat widgets as abstract entities without immediate concern to their implemen-
tation on various client environments.
A major goal of this approach is to develop user interfaces that can become
more responsive and intuitive according to the capabilities of the client environment,
while affording all of the functionality of the application, even at the lowest level
of capabilities. Here, the functionality of the application refers to what can be done
with the application and not necessarily how it is performed. In the CDX application,
for example, the user must use the buttons in order to navigate the map at Tier 1,
but at Tier 2, the map becomes responsive to mouse control. Tier 1 users can still
fully navigate the map, even though they need to do so via a slightly more primitive
interface and changes require a full request/response cycle with the server. Tier 2
map users can still use the familiar button interface to navigate the map and both
visual representations (assuming that basic CSS is supported by the Tier 1 clients)
of the maps are identical at both tiers.
While the RFDE approach removes, or at least significantly reduces, the need
for a Web application developer to produce device or platform specific interface
elements, it does not preclude the development of native interface implementations.
In fact, the REST uniform interface constraint supports and facilitates the develop-
ment of these native interfaces. Devices can use their own implementations of the
10 A REST Framework for Dynamic Client Environments 257
interface widgets and populate any derived values via requests through the widget
interface, in the same way that the CDX Tier 2 clients do. Optimized clients for the
Climate Data Explorer are currently under development for several popular mobile
device platforms.
The current version of the RFDE server implementation does not include a
uniform and generic method for describing the logic of an application template (e.g.,
the widgets, layout, constraints, and event handlers that comprise the template);
however, the development of such a language is an important next step in our
research. This language would allow native implementations to utilize the same
application templates that the Web applications use and reduce the development
costs associated with adapting new application templates and updating existing
templates as they are improved.
One potential drawback to the RFDE approach is that each widget needs to be
implemented multiple times. For example, in order to create a widget for CDX,
a Java class that implements the Tier 1 widget needs to be written, a JavaScript
analog needs to be written for the Tier 2 client-side implementation, and (for some
of the widgets) the RFDE widget interface needs to be updated to generate a JSON
representation for the value of the widget. On the other hand, once the underlying
widgets have been implemented, an application can be developed that automatically
supports the various levels of capabilities of its clients – the alternative would be
to develop multiple versions of the same application. One solution to the problem
of handling the dual implementation of the widget library, and one that we plan on
investigating for the next version of the framework, is the development of a language
or library that can be used to write widgets that will automatically compile both
the client-side JavaScript libraries as well as the server-side implementation from a
single source.
Acknowledgements This work was supported in part by the U.S. National Science Foundation
grant EAR-1027960 and the University of Maine.
References
Cesare Pautasso, Olaf Zimmermann, and Frank Leymann. Restful web services vs. “big” web
services: making the right architectural decision. In WWW ’08: Proceeding of the 17th
International Conference on World Wide Web, pages 805–814, ACM, New York, NY, USA,
2008.
Dean Jackson and Craig Northway. Scalable vector graphics (SVG) full 1.2 specification.
WD not longer in development, W3C, April 2005. http://www.w3.org/TR/2005/WD-SVG12-
20050413/.
Douglas Crockford. The application/json Media Type for JavaScript Object Notation (JSON). RFC
4627 (Informational), 2006.
Jesse James Garrett. Ajax: A new approach to web applications. 2005.
John Grundy and Biao Yang. An environment for developing adaptive, multi-device user interfaces.
In AUIC ’03: Proceedings of the Fourth Australasian user Interface Conference on User
Interfaces 2003, pages 47–56, Australian Computer Society, Inc., Darlinghurst, Australia,
Australia, 2003.
258 E. Albert and S.S. Chawathe
John Wells and Chrisina Draganova. Progressive enhancement in the real world. In HT ’07:
Proceedings of the Eighteenth Conference on Hypertext and Hypermedia, pages 55–56, ACM,
New York, NY, USA, 2007.
Mir Farooq Ali and Marc Abrams. Simplifying construction of multi-platform user interfaces using
UIML. In European Conference UIML, 2001.
B. Randell, P. Lee, and P. C. Treleaven. Reliability issues in computing system design. ACM
Comput. Surveys (CSUR), 10(2): 123–165, 1978.
Rodrigo de Oliveira and Heloı́sa Vieira da Rocha. Towards an approach for multi-device interface
design. In WebMedia ’05: Proceedings of the 11th Brazilian Symposium on Multimedia and the
Web, pages 1–3, ACM, New York, NY, USA, 2005.
Roy T. Fielding and Richard N. Taylor. Principled design of the modern web architecture. ACM
Trans. Internet Technol., 2(2):115–150, 2002.
Roy Thomas Fielding. Architectural Styles and the Design of Network-based Software Architec-
tures. PhD thesis, University of California, Irvine, 2000.
Ryan McFall and Charles Cusack. Developing interactive web applications with the google web
toolkit. J. Comput. Small Coll., 25(1): 30–31, 2009.
Stephen Edwards, Manuel A. Prez-quiones, Mary Beth Rosson, Robert C. Williges, Constantinos
Phanouriou, and Constantinos Phanouriou. UIML: A device-independent user interface markup
language. Technical report, 2000.
Todd Parker, Scott Jehl, Maggie Costello Wachs, and Patty Toland. Designing with Progressive
Enhancement: Building the Web that Works for Everyone. New Riders Publishing, Thousand
Oaks, CA, USA, 2010.
Vlad Stirbu. A restful architecture for adaptive and multi-device application sharing. In WS-REST
’10: Proceedings of the First International Workshop on RESTful Design, pages 62–66, ACM,
New York, NY, USA, 2010.
Chapter 11
From Requirements to a RESTful Web Service:
Engineering Content Oriented Web Services
with REST
Petri Selonen
Abstract This chapter presents an approach for proceeding from a set of require-
ments to an implemented RESTful Web service for content oriented systems. The
requirements are captured into a simple domain model and then refined into a
resource model. The resource model re-organizes the domain concepts into address-
able entities: resources and interconnecting links, hypermedia representations, URIs
and default HTTP operations and status codes. The approach has emerged from the
experiences gained during developing RESTful Web services at Nokia Research
Center.
Introduction
REST and Resource Oriented Architecture (ROA) (Richardson and Ruby 2007) are
particularly well suited for content oriented Web services whose core value are in
storing, retrieving and managing interlinked content through a uniform interface.
While REST has gained significant popularity as the architecture for Web services,
there is a notable lack of methods and modeling notations for developing RESTful
services from requirements. There is a need for communicating the requirements
and design intent to the different stakeholders, as well as to map the requirements
and new features to the existing implementation in a way that preserves consistency
of the API and supports service evolution over time.
Probably the best known formulation of how to design RESTful Web services
has been presented by Richardson and Ruby which involves finding resources and
their relationships, selecting uniform operations and respective response codes for
each resource, and defining their data formats. The formulation is too abstract to
be followed as a method and does not facilitate communication between service
P. Selonen ()
Nokia Research Center, Visiokatu 1, Tampere 33720, Finland
e-mail: [email protected]
architects and other stakeholders. Even with a priori content oriented services,
it is often a non-trivial exercise to refine a functional specification to resource-
oriented, descriptive state information content. According to our experiences, many
developers find it hard to make a paradigm shift from object oriented design that
emphasizes hiding state-related data behind task-specific operations of an instructive
interface. Such API centric thinking has a tendency to make resulting Web services
look more like a collection of unrelated APIs instead of a set of interlinked content
accessible using a uniform interface.
This chapter presents a systematic but light-weight approach for proceeding from
a set of requirements to an implemented RESTful Web service and integrating
new requirements with an existing system for content oriented services. The
requirements are first collected into a domain model – expressed with UML class
diagrams – which is essentially a structural model describing the domain concepts,
their properties and relationships, and annotated with information about required
searching, filtering and other retrieval functionality, and constraints. The domain
model is then gradually refined into a resource model that is used to derive the
resources and interconnecting links, representations, assigned URIs, and default
HTTP operations and response codes of the Web service. The concepts of a
resource model can be further mapped to implementation level concepts in service
specifications, database schema and source code.
The approach has emerged during the development of a RESTful Web service for
building Mixed Reality services at Nokia Research Center and reported in Selonen
et al. (2010a,b). The gained experiences suggest it supports architects’ communica-
tion with the service clients, and perhaps more importantly, with software engineers
not familiar with REST and ROA. The presented approach helps bringing in new
features to the system in a non-intrusive way in a rapid pace while supporting
traceability of requirements and actual implementation.
The chapter is organized as follows. In “Overview of the RESTifying Approach,”
we introduce the “RESTifying approach” with an overview of the process, domain
models, resource models and discussion on how to refine the former into the latter.
“Example Web Service: Social Points of Interest” gives a step-by-step example on
how to apply the approach for a simple Web service starting with requirements and
domain model, and refining the domain model into resource models and respective
components of a RESTful Web service. “From Resource Model to Implementation”
discusses how to implement the service defined by the resource model. Finally,
“Concluding Remarks” gives concluding remarks.
«artifact»
Service Requirements
Domain Model
The domain model describes concepts of a system, the attributes and attribute types
related to the concepts, sub-concepts of the concepts and filtering criteria related
to the concepts. As it represents the key concepts of the system and their attributes
using the vocabulary of the problem domain, it can be used to communicate the
system requirements among the system stakeholders, and as a starting point for
software development. It is in principle a subset of a vanilla class diagram with a
few additional annotations.
262 P. Selonen
Concept ConceptTwo
ref
identifier readOnlyAttribute : Another Type
anAttribute : Some Type 0..1
*
Subconcept
anotherAttribute
Since content oriented Web services have by definition their value in storing,
retrieving and managing content, we assume that a domain model with additional
constraints for queries and attribute values can capture essentially enough informa-
tion to be used as the main source for building the service.
Figure 11.2 illustrates a simple domain model. It has concepts, concept attributes
and associations between the concepts. Attributes can have types; associations can
have multiplicities (cardinalities) and they can be directed and composite (whole–
part relationships). The domain model profile package shown in Fig. 11.1 simply
defines the allowed UML elements: classes, associations, attributes, generalizations
and comments.
Looking at the domain model, one can outline a respective RESTful Web service:
classes look like candidates for resources, attributes as constituents of resource
representations, and associations as links. However, it is not obvious how exactly
the links are represented, what URIs are assigned to exposed resources, what HTTP
operations are allowed per resource and how creation, retrieval, update and deletion
of resources is to be allowed.
Resource Model
«stereotype»
«stereotype»
ref sub
Resource
[Association]
[Class]
uri : String
sub
«stereotype»
ref
[Association]
«stereotype»
sub
Container
[Class]
«stereotype» «stereotype»
sub Item Property
[Class] [Property]
«stereotype»
Projection
[Class]
Figure 11.3 shows the concepts of a resource model as a resource model profile.
Items represent individual resources having a state that can be retrieved, created,
modified and deleted. Containers can be used for retrieving collections of items
and creating new ones. Projections are filtered views to containers. Resources can
have sub-resources and links to other resources. In addition to the resources and
interconnecting links, a resource model instance can be used to infer the other
components of a RESTful Web service: resource representations, assigned URIs,
and default uniform HTTP operations and response codes. The resource model is
formalized into a UML profile, where each element becomes a stereotype.
Representation for Resource r is as follows:
<r.name>
<atom:link rel="self" href="r.uri"/> # self link
# for each property p where p belongsto r.property
<p.name>value of property p</p.name>
# for each subresource s where s belongsto r.sub
<s.name>
# link to a sub resource
<atom:link rel="self" href="s.uri"/>
</s.name>
</r.name>
264 P. Selonen
In the proposed model, Containers and Projections do not have properties and
thus neither do their representations. Each Item i of type T has exactly one id
attribute that defines a unique name (among other items of type T). For Containers,
id attribute is the name of the container. A relative URI for Resource r is defined as
follows:
The default HTTP operations and response codes for resources are as follows:
Item GET, PUT, DELETE Retrieve, create or update, and remove an item
Container GET, POST Retrieve collections of items and create a new item
Projection GET Retrieve a collection of items based on particular
criteria
The default status codes for each resource and request can be selected from the
HTTP status codes: 200 OK for successful operation, 201 Created for successfully
creating a new resource, 400 Bad Request for requests with malformed represen-
tations, 404 Not Found for non-existing resources, 405 Method Not Allowed for
unsupported methods and so forth. The implemented service can decide a finer
level of granularity and select more refined communication patterns at will. For
example, if a resource contains read-only properties or properties that can only be
incremented, attempting to modify them might result in 403 Forbidden or 409
Conflict status codes.
In the domain model, each concept represents an aspect of the system that will
become an addressable resource. Concepts can link to other concepts. Links will
become links in the hypertext representations. Concepts can also have subconcepts
which are parts whose existence is tied to the parent concept. Subconcepts that do
not warrant individually addressable resources can be marked as data types (UML
dataType stereotype).
Concepts can have attributes that define their state and representation. An id
attribute represents a textual identifier that will be used when constructing the URI
of the concept. For this presentation, we define two additional types of attributes: a
readOnly attribute is a read only attribute that will be set by the system and
that the user cannot modify, and an appendOnly counter attribute whose value
11 From Requirements to a RESTful Web Service: Engineering Content Oriented : : : 265
can only be incremented. The domain model elements can be mapped to resource
model elements roughly as follows:
1. Domain classes represent the domain concepts: the content the service is to
manage. If not defined otherwise, classes will become item resources:
addressable resources of their own right with a URI and representation.
2. Attributes of classes as well as data types belonging to classes will become
attributes of respective item resources and manifest themselves in the
resource representations.
3. Associations represent relationships between the concepts and they will become
ref associations between resources that appear as links in the representa-
tions. Bi-directional associations (i.e. associations navigable to both directions)
are represented as two directed ref associations.
4. Composite associations represent whole-part relationships between resources
and subresources, and become sub associations between resources.
5. Associations representing collection of elements – i.e. associations having upper
multiplicity bound greater than 1 – will manifest themselves as container
resources containing item resources.
6. Notes attached to classes informally describing queries (searches, filtering) are
mapped to projection resources with attributes for each query criterion.
Query attributes that refer to resource attributes are marked with index.
7. Attributes constrained informally in notes are marked with respective constraint
stereotypes. For example, if an attribute is read only (e.g. whose value is to be set
by the system), one can use readOnly. There can be common constraints,
but it is usually up to the service architect to identify and pre-define such
constraints and how they are mapped to implementation level concepts.
In “Example Web Service: Social Points of Interest” the above approach is
applied to a small but non-trivial Web service for social Points of Interest.
To exemplify the approach, we develop a simple service that allows users to create
and share personal points of interests. Consider the following high-level service
description:
A user can create points of interests (POIs) that can have a title and a description. Users
can assign a location (as coordinates) and tags to a POI. Other users can comment POIs and
rate them with a thumb up or down vote. Users can search for POIs based on their location
(radius and bounded box search), their tags and their popularity (view count). All created
content is public, but only the authors of any particular content element can modify and
delete them; other users can only read content made by somebody else.
The requirements clearly describe a content oriented Web service: its value is in
creating, retrieving, modifying and deleting content, with additional requirements
on searching for content and enforcing simple constraints.
Same requirements can yield several similar alternative domain models. Design
decisions like whether one resource is a subresource of another one or just linking to
each other, or whether a particular property of a resource is promoted to be exposed
as a subresource with its own URI, will lead to slightly varying service descriptions.
Regardless of the stucture of the particular domain model, however, we can derive
a RESTful Web service interface exposing the information content present in the
model. If the resulting API turns out to have unwanted or missing features – for
example, resources that are always retrieved at the same time but not connected in
the domain model, resulting in unnecessary client–server round-trips – the domain
model can be adjusted accordingly.
Figure 11.4 shows the domain model for the POI Web service derived from the
service description given above. While it is obviously not the only possible model,
it nevertheless should be a reasonably good approximation of the requirements.
The domain model defines following structural features:
• User of a system has a unique username and associations to owned POIs,
Comments and Ratings.
• POI is owned by a User. It has a title and a description, (preparing for the
inevitable future request) creation and modification date, and total number of
thumbs up and down. POIs have subelements Viewcount, Ratings, Tags and at
most one Location. POI can link to arbitrary amount of Comments.
• Viewcount is modeled as a separate class to emphasize increasing view count
being (an implicit) requirement.
• Location has a longitude, latitude and altitude.
• Tag is a simple textual element.
• Comment has a text body and an association to the commented POI.
• Rating has a thumb attribute for thumbs up or down. Each Rating points to
exactly one User and one POI.
11 From Requirements to a RESTful Web Service: Engineering Content Oriented : : : 267
A User has a
unique username
Search by Location
(radius, bounded box)
User
owns
username : String
0..1 1
Search by Tag
1 owns
owns
Search by *
*
popularity POI
Comment
title : String
body : String
description : String * *
thumbs_up and created : date
thumbs_down are the modified : date Rating
number of thumbs thumbs_up : Integer thumb : RATING
up/down ratings given by thumbs_down : Integer 1 *
users
«enumeration»
0..1 RATING
1
Location * UP
Viewcount : Integer lon : float Tag : String DOWN
lat : float
alt : float
Fig. 11.4 Domain model for social points of interest Web service
«Root»
«sub» «sub»
Point of Interest Service
{URI=http://example.com}
«sub»
1 1 1
«Container» «Container» «Container»
POIs Users Comments
Domain model concepts that are not subconcepts of others but defined as first class
entities become root level resources. Resource model for the root level containers
is shown in Fig. 11.5. Each class that does not have an owning composite class
becomes a root level item: POI, User and Comment. Unless defined otherwise,
we assume there can be an arbitrary amount of each root element and thus create
container elements for the items. As a convention, we use a plural form of the
contained item name for the containers: POIs, Users and Comments. The root
element is for illustration only, representing the Web service to be built and defining
its root URI path. Resources have URIs and thus need an identifier: for containers,
the identifier is the container name; for items, we can define one explicitly by an
attribute with stereotype id (User.username) or omit it and get one generated
by the system.
Following the approach defined in “Resource Model,” the implied URIs and
partial resource representations are as follows (with the “http://example.com” prefix
omitted):
The operations and HTTP status codes follow from the default operations defined
for containers and items. Note that following the above definition, a User is just
another resource in the service. In practice, we probably want to restrict creation of
new Users to be done through some specific administrative interface. In principle,
though, there is no fundamental need why User resources cannot be accessed
through the same unified interface. The resource model further implies the following
representation fragments:
<pois xml:base="http://example.com/">
<atom:link rel="self" href="pois"/>
<poi><atom:link rel="self" href="pois/123"/></poi>
<poi><atom:link rel="self" href="pois/45"/></poi>
</pois>
<poi xml:base="http://example.com/">
<atom:link rel="self" href="pois/123"/>
</poi>
Resource model for a Point of Interest is shown in Fig. 11.6. The POI, Viewcount,
Location and Tag elements of the domain model are refined into respective
resource model concepts. POI, Viewcount, Location and Tag elements become
item elements with respective attributes, with the former being a composite
class containing the three latter using a sub association. We decide not to
expose view count or tags as first class elements with URIs, so we define them as
property elements. We use two special but generic stereotypes to represent the
attribute constraints: readOnly for read only attributes (created and modified
dates are set automatically by the system) and appendOnly for attributes whose
value can only be increased (viewcount).
The resource model in Fig. 11.6 implies the following resources:
«Item»
POI
«id»id
title : String
description : String
«readOnly»created : date
«readOnly»modified : date
The resource model further implies the following resource representation with
location subresource inlined (x-rest-inline: location, see 11):
<poi xml:base="http://example.com/">
<atom:link type="self" href="pois/123"/>
<title>A title for a POI</title>
<description>A description for a POI</description>
<viewcount>132</viewcount>
<tags>
<tag>A tag</tag>
<tag>Another tag</tag>
</tags>
<location>
<atom:link type="self" href="pois/123/location"/>
<lat>61.4467</lat>
<lon>23.8575</lon>
<alt>0.0</alt>
</location>
</poi>
Search by Tag
«sub»
1
Order by popularity * «Projection» «sub»
«Item» radius
item
POI
«index»loc : Location
* «ref»
radius : float
«sub»
1
item «Projection» «sub»
area
* «ref»
item * item * «index»loc1 : Location
«index»loc2 : Location
1
«Projection»
«ref» tag
«index»tag : Tag : String
1
«Projection»
«ref»
most_viewed
order : String
Fig. 11.7 Point of interest resource model for projections: search by radius, area, tags, and view
count
Following from the domain model fragment shown in Fig. 11.4 and the previous
resource models, we further derive the projections corresponding to the different
queries. Figure 11.7 shows a resource model for POI related projections. We
build a projection for each identified query: search by radius, search by
bounded box (“area”), search by a tag and order by popularity (“most viewed”).
Each projection is effectively offering a projection to the resources contained by
the POIs container, making them are sub subresources of the POIs container.
As they do not own the resources of their parent container, they instead produce a
set of ref resource references depending on the query parameters provided by
the user. The projection attributes define the search parameters; the ones referring
directly to POI attributes can be marked with index stereotype to hint later in
the implementation phase that the property is used for indexing. Search functionality
is obviously critical for the performance of a Web service. Details beyond simple
searching over indexed attributes are beyond the scope of the chapter.
272 P. Selonen
/pois?q=radius GET
&loc.lon={poi.location.lon}
&loc.lat={poi.location.lat}
&radius={radius}
/pois?q=area GET
&loc1.lon={poi.location.lon}
&loc1.lat={poi.location.lat}
&loc2.lon={poi.location.lon}
&loc2.lat={poi.location.lat}
/pois?q=tag&tag={poi.tags.tag} GET
/pois?q=most_viewed&order={String} GET
/pois?lon=23.8575&lat=61.4467&radius=0.5&
tag=restaurant&tag=food&order=desc
<pois xml:base="http://example.com/">
<atom:link rel="self" href="pois"/>
<atom:link rel="search"
type="application/opensearchdescription+xml"
href="pois"/>
<poi><atom:link ref="self" href="pois/123"/></poi>
<poi><atom:link ref="self" href="pois/456"/></poi>
</pois>
A client can have design time knowledge of the supported query templates, but
this couples the client to the service. The URI templates implied by the projection
resources can also be mapped to a service description that a client can access at run
time. In the above representation, however, we have chosen to use the OpenSearch
content type. This way the client can dynamically retrieve descriptions of the
currently supported projections for a container.
11 From Requirements to a RESTful Web Service: Engineering Content Oriented : : : 273
«Item»
«ref» User «ref»
«ref» «ref»
«id»username : String
0..1 1
* *
«Item» «Item»
POI Comment
«ref»
«id»id body : String
0..1
From the domain model in Fig. 11.4, we can infer that User has a collection of links
to POI elements and Comment elements, POI has a collection of links to Comment
elements, and Comment has a link to POI and a User. This is formalized in the
resource model shown in Fig. 11.8. The collections of links are projection
elements containing ref links to the items. POI and Comment has a ref
reference pointing back to a User. The bi-directional association between POI and
Comment has been broken down to two relationships: a ref relationship from
a Comment to POI and a Comments projection containing a collection of
links from POI to Comments.
The implied new resources are as follows:
/users/fuser.usernameg/pois GET
/users/fuser.usernameg/comments GET
/pois/fpoi.idg/comments GET
274 P. Selonen
Effectively, the new POI and Comment projection elements are conve-
nience URIs to the respective containers with the username and POI id as context.
For example, the first URI implies a query /pois?user=user.username.
The implied new resource representation fragments are as follows. For User:
<user xml:base="http://example.com/">
<atom:link rel="self" href="users/bob"/>
<username>bob</username>
<pois>
<atom:link rel="self" href="users/bob/pois"/>
</pois>
<comments>
<atom:link rel="self" href="users/bob/comments"/>
</comments>
</user>
For POI:
<poi xml:base="http://example.com/">
<atom:link rel="self" href="pois/123"/>
<comments>
<atom:link rel="self" href="pois/123/comments"/>
</comments>
<user>
<atom:link rel="self" href="users/bob"/>
</user>
</poi>
For Comments:
<comments xml:base="http://example.com/">
<atom:link rel="self" href="comments"/>
<comment>
<atom:link rel="self" href="comments/453"/>
</comment>
<comment> . . . </comment>
</comments>
11 From Requirements to a RESTful Web Service: Engineering Content Oriented : : : 275
<comment xml:base="http://example.com/">
<atom:link rel="self" href="comments/453"/>
<body>Comment text</body>
<user><atom:link rel="self" href="users/bob"/></user>
<poi><atom:link rel="self" href="pois/123"/></poi>
</comment>
/pois/{poid.id}/rating/{rating.id}
<rating xml:base="http://example.com/">
<atom:link rel="self" href="pois/45/rating/1"/>
<thumb>DOWN</thumb>
<user><atom:link rel=’self’ href=’users/bob’/></user>
<poi><atom:link rel=self’ href=’pois/45’/></poi>
</rating>
After the domain model has been refined into a resource model, we want to trace
back the service requirements and see how the implied RESTful interface fulfills
them. Figure 11.9 shows four example sequence diagrams showing the HTTP level
276 P. Selonen
201 Created
201 Created
Location: /pois/1 Location: /comments/1
GET /pois?tag=cafeteria
x−rest−inline: comments
200 OK
<pois>
<atom:link rel="self" href="/pois" />
<poi>
<atom:link rel="self" href="/pois/1" />
<title>Kahvila Runo</title>
Only authors of particular <description>My favorite cafe</description>
<tag>cafeteria</tag>
content element can <comments>
delete them <comment>
Client Service <atom:link rel="self" href="/comments/1" />
<body>Nice cafeteria!</body>
<user>
DELETE /pois/1 <atom:link rel="self" href="/users/mary" />
Authorization: Mary </user>
</comment>
</comments>
</poi>
401 Unauthorized </pois>
interaction between a client and the service: creating a POI, commenting a POI,
attempting to remove a POI made by a different user and finally searching for POIs
based on a tag with comments inlined.
Table 11.1 Example implementation binding to Java EE, MySQL, Hibernate, and Restlet
Representation Model (Hibernate, Persistence
API (Restlet) (XML/JSON) Java EE) (MySQL)
Item Restlet resource Representation A native Java object Items are rows
bound to the parsing/genera- (POJO) in respective
URI. Supported tion based on generated for database table
default the item each item with a with columns
operations are attributes. Hibernate Data specified by
GET, PUT and Subresources Access Object item attributes.
DELETE. inlined per and binding to References map
request basis. database to foreign keys.
elements.
Container Restlet resource Representation Basic retrievals to Containers are
bound to the parsing/genera- database, using database tables.
URI. Supported tion delegated item mappings.
default to Items.
operations are
GET and
POST.
Projection Implemented on Representation Extended retrievals Stored procedures
top of generation to database, for more
respective delegated to using item advanced
Containers. Container. mappings. database
queries. Tables
implied by
Container.
Concluding Remarks
to capture domain concepts and together with additional constraints uses them to
derive a Web service interface description. It further facilitates capturing the service
requirements and communicating them to different stakeholders in a consistent
manner with standard software engineering artifacts instead of ad hoc representation
examples. The presented approach has emerged from the experiences gained during
development of several RESTful Web services. Our goal has been to move away
from designing individual APIs to bringing providing access to all content through
a uniform programmable Web interface.
The approach has been successfully applied to several service domains that have
their core value in storing, retrieving, and managing interlinked content. We argue
it is possible to transform any domain model conforming to the domain model
profile – i.e. containing only classes, attributes, associations, and generalizations –
to a resource model and therefore to an implemented RESTful Web service.
Consequently, the approach should be applicable to any service whose requirements
can be captured with a domain model and simple constraints on how to access and
retrieve content. How to refine a service whose value is in algorithms, processes and
complex transactions to resource-oriented, descriptive state content is a valid design
problem on its own right.
The RESTifying approach is currently applied manually for designing new
services and integrating them with existing Web service platforms. As a next
step, we are hoping to experiment with building tool support for the approach: to
proceed from a domain model to a resource model and further to a RESTful service
description, and integrating the approach to our existing modeling environment.
As future research, with proper Web service infrastructure, we hope to be able to
generate most of the server side code and client side stubs directly based on the
domain model, allowing new resources be added in a generative and declarative
way for a consistent Web service interface.
Acknowledgements The author would like to thank Markku Laitkorpi, Petros Belimpasakis, Arto
Nikupaavola, Yu You and Vlad Stirbu, the former NRC Service Software Platform team and NRC
Mixed Reality Solutions program for their valuable contribution.
References
M. Laitkorpi, P. Selonen, and T. Systä. Towards a model-driven process for designing restful web
services. In IEEE International Conference on Web Services, ICWS 2009, ICWS, Los Angeles,
CA, USA, 6–10 July 2009, pages 173–180.
L. Richardson and S. Ruby. ReSTful Web Services. O’Reilly Media, 2007. pages 108–136.
P. Selonen, P. Belimpasakis, and Y. You. Developing a restful mixed reality web service platform.
In Proceedings of the First International Workshop on RESTful Design, WS-REST ’10, pages
54–61, ACM, New York, NY, USA, 2010.
P. Selonen, P. Belimpasakis, and Y. You. Experiences in building a restful mixed reality web service
platform. In B. Benatallah, F. Casati, G. Kappel, and G. Rossi, editors, Web Engineering,
volume 6189 of Lecture Notes in Computer Science, pages 400–414. Springer, Berlin,
Heidelberg, New York, 2010.
Chapter 12
A Framework for Rapid Development
of REST Web Services for Integrating
Information Systems
Introduction
The concept of integration has been present in the software development domain
in various forms for the last two decades. Over the years, integration approaches
evolved from simple remote procedure calls (Brose et al. 2001) and message passing
systems (Monson-Haefel and Chappell 2000) to service oriented solutions and have
found their way to become integral parts of programming platforms like J2EE or
.NET (Erl 2005). Recent years have witnessed an unprecedented shift in distributed
computing towards Service-Oriented Computing (SOC) (Chang et al. 2006), which
is gaining prominence as an efficient approach for integrating applications in
heterogeneous distributed environments (Erradi et al. 2006). The most popular
branch of SOC research is dedicated to advances in Service Oriented Architecture
and SOAP Web services (Curbera et al. 2005), but the growing popularity of the
L. Hagge ()
Deutsches Elektronen-Synchrotron, Notkestrasse 85, Hamburg 22607, Germany
e-mail: [email protected]
Web 2.0 (Musser and O’Reilly Radar Team 2006) concept has brought increased
attention to the REST architectural style as an alternative way of building service
oriented environments (Howerton 2007; Vinoski 2007).
Building an integrated software environment in an enterprise often requires
developing large amounts of Web services. The integration efforts can be greatly
reduced by using a specialized framework for their development. Providing such
tools that simplify software development in integration projects is essential for
optimizing their efficiency and cost.
This paper describes a framework for rapid development of REST Web services
which are suitable for integrating information systems. It first illustrates the
application scenario with a simple example, which is used to explain the proposed
integration architecture. Then, it introduces the framework architecture, putting
particular emphasis on code reusability as basis for rapid development. The next
section describes three application examples of the framework, and the final section
summarizes experience gained and outlines possible next steps. The paper focuses
on the general framework design principles and the role of REST, independent of
particular implementation technologies.
One of the most important choices to make when building an integration solution
is to select an appropriate integration approach and suitable technologies for its
realization. These choices can vary depending on the characteristics of the software
environment and the particular goals of the specific integration project. This section
introduces an example integration scenario and uses it for deriving an architecture
for integrating enterprise information systems. The architecture is based on a layer
of REST Web services which provide unified access to the information systems
of the integrated environment. The section concludes by discussing those types of
integration for which REST is well suitable, and those for which it is not.
Integration Architecture
Figure 12.1 (a) shows a simplified information model for equipment documentation.
It states that equipments have descriptions in terms of documents, where equipments
can be complex items which are built using other equipments, and documentation
can consist of various documents with cross-references and dependencies. The
schema has to be adapted and specialized for each particular business, yielding an
ontology of the target application area. An example is given for facility planning
and plant design (b): Facilities are organized into functional subsystems. They
comprise functional units, are driven by power supplies, are controlled by safety
12 A Framework for Rapid Development of REST Web Services for Integrating : : : 281
Process Drawing
a Has Description Ctrl. System Archive
Equipment Document
Has Descr. Technical
Functional Drawing
Subsystem
uses refers to Has Descr.
made from depends on depends on
uses
Has Descr. 3D
Example: Facility Planning Power
Design Supply Model
Functional Facility
Specification
Unit
uses dep. on uses synch dep.on dep.on
uses
Has Description Safety
Safety 3D Has Descr. Design
Monitor uses Model Monitor
Specification
Functional Has Description
dep. on
Power uses Subsystem Has Description Power Operation
Technical Supply
Supply Manual
Drawing
Has Description Has Description refers to
Has Description dep. on synch
Technical Technical
Technical refers to Operation Data Sheet Data Sheet
Data Sheet Manual Equipment Document
b Database c Management
monitors, etc., all of which are special types of equipments. They are described by
a variety of technical documentation, including specifications, design models and
drawings, work instructions, and operation manuals, all of which are special types
of documents.
When it comes to implementation, ideally a single information system (IS) would
support the entire ontology and its business processes, but in practice objects and
functionalities are often spread over a number of systems. Figure 12.1 (c) shows
a typical example for a deployment scenario: Operators use a process control
system (PCS) for setting-up and running of the facility. Technicians use equipment
databases (EDB) to keep track of the inventory and organize regular inspections and
repairs. Management and staff use a central document management system (DMS)
for review, approval and archival, while designers and engineers use a dedicated
CAD drawing archive (CDA) for design models and drawings.
The information systems are not independent as there are business requirements
which extend beyond the scope of individual systems. Consider the following
examples:
1. An operator who may need to respond to an alarm in the PCS, e.g. of an over-
heated power supply, would benefit from navigational support to the appropriate
operation manual in the DMS.
2. A planned subsystem update, e.g. for improved performance, would require lead
engineers to update specifications in the DMS, and then propagate necessary
change information to different engineering groups, who then implement the
change and update their equipment information and documentation accordingly.
The objective would be to coordinate the entire business (change) process
independent of any IS boundaries.
282 L. Hagge et al.
Integration Application
e.g . Information Portal, Workflow Engine Ontology
Has Description
Management
Ctrl. System
Specification
Equipment
Data Sheet
Data Sheet
Subsystem
Document
Functional
Database
Operation
Technical
Technical
refers to
Process
Monitor
Manual
Design
Supply
Supply
Safety
Power
Power
uses
PIM ONTOLOGY
+
information about
target platforms
VS. transform
transform
information about
intended abstraction level
+
PSM PSM PSM
PSM PSM PSM
A B C
A B C
Ontology Canrepresentthe
Can represent the
Consumer1:
Consumer 1:Integration
IntegrationApp.
App. Consumer
Consumer22 sameIS
same ISactingin
acting in
bothroles
both roles
access resources accessresources
e.g. C and D e.g. A and B
The emerging ontology has to be checked for consistency and compliance with the
original IS data models. It will stabilize in an iterative process. Figure 12.4 redraws
the integration architecture from a resource-centric perspective and emphasizes, that
ISs can act both as resource providers and consumers.
In this example, approving items denotes that they are read, signed and this
way endorsed by responsible persons. Such approvals or sign-offs are common
functionalities of information systems, often provided as workflows. To remain
compliant with the REST approach, such workflows also have to be represented
and treated as resources. This requires translating all functional aspects of workflow
into data structure and defining it as an ontology class. For manipulating workflow,
the standard CRUD operations can be used with the following interpretation:
• Create – start workflow
• Retrieve – check workflow status
• Update – alter workflow execution
• Delete – abort workflow
The above example would then be re-written as
1. CREATE change request (cr-id, title, description, author, . . . )
2. CREATE approval workflow (cr-id. reviewer-1, reviwer-2, . . . )
3. UPDATE specification (. . . )
4. ...
If it turns out that reviewer-1 is not available, an alternative reviewer may be
assigned by updating the approval workflow. Authors may inquire how many
reviewers have already processed the request by RETRIEVing the workflow status,
and in case they discover mistakes, withdraw the request for approval by DELETing
the workflow.
The described scenario shows how standard CRUD operations can be used to
manipulate workflows within an information system.
The scenario neglects that in a “real” business process, the different actions
would be conducted by different users. This would require additional steps of
routing information to process participants and asking them to perform their actions
and acknowledge their completion. Routing, acknowledging, etc. can be treated in
the same way as described above for the approval workflow, which leads to the
conclusion that any business process can be implemented with this schema.
In case of complex processes, the granularity of resources should be carefully
considered. Defining too unspecific resources can lead to insufficient control over a
process, while too detailed resources may impose too many actions on the IS users
and thus become inefficient. On the other hand, building a library of general-purpose
process building-blocks will allow quick and easy future process modification by
simply rearranging items in the process sequence.
The proposed integration approach has been specifically developed for integrating
business information systems. It assumes an existing environment of legacy infor-
286 L. Hagge et al.
This section introduces a REST Web services framework with specific emphasis
on rapid development. Building an integrated enterprise environment, which often
consists of dozens of individual applications that should cooperate, requires devel-
oping large families of Web services. The described framework can considerably
speed up the development process by achieving high levels of code reuse and easing
code maintenance. The section presents the framework architecture, introduces the
strategy for code reuse, and describes how the framework is effectively used in large
environments.
Objectives
uses
RESTWebService SystemDriver
SystemInteracting
EDB
Document
EDB
Equipment
PCS
Equipment …
WebService Driver Driver Driver
use
EDB use
Document_WS
use
EDB
CRUDWebService
Equipment_WS
PCS
Operation Controller Equipment _WS …
Fig. 12.6 Framework structure
• System Drivers (SD) provide functionality for accessing specific ISs, such as
connecting to and disconnecting from the IS, beginning and finalizing transac-
tions, and creating, locating, retrieving, modifying and deleting resources. System
Drivers encapsulate the IS APIs
Framework Structure
Figure 12.6 presents the structure of the framework and the mapping of its classes
to functional layers. The left side of the class hierarchy contains classes which
implement the operational skeleton of a Web service, while the right side represents
system specific code. Figure 12.7 illustrates the interplay of the different classes
in an activity diagram. Partitions represent framework classes, and the allocation
of actions shows their implementing classes. Structured activity blocks spanning
multiple partitions represent abstract methods.
The topmost RESTWebService abstract class encapsulates functionality which
is common to all REST Web services and realizes the Request–Response Pro-
cessor. The class is responsible for handling incoming requests, processing them
and passing their parameters together with stored configuration to the abstract
action() method for operation-specific processing. Upon successful completion of
the operation, the results are formatted and returned. In case of failure, exception
handling takes place and error messages are returned.
290 L. Hagge et al.
Load
RESTWebService
configuration
connection
[no] Compose error Output
security and
message results
authentication [yes]
ok ? [no]
Parse [yes]
request [no]
Parameters
[yes]
valid ?
getDriver()
System
Connect Disconnect
to system from system
WebService
CRUD
POST
SystemDriver
Create
GET
Retrieve
PUT
Validate system Connect Update
DELETE Disconnect
specific parameters Delete
EDB PCS
Document Equipment Equipment
Create Retrieve Update Delete Create Retrieve Update Delete Create Retrieve Update Delete
RRP RRP RRP RRP RRP RRP RRP RRP RRP RRP RRP RRP
sis sis sis sis sis sis sis sis sis sis sis sis
cC rC uC dC cC rC uC dC cC rC uC dC
SD SD SD SD SD SD SD SD SD SD SD SD
… … …
Driver Driver Driver Driver Driver Driver Driver Driver Driver Driver Driver Driver
sd sd sd sd sd sd sd sd sd sd sd sd
c c c c c c c c c c c c
r r r r r r r r r r r r
u u u u u u u u u u u u
d d d d d d d d d d d d
implementation progress
Therefore, drivers for specific ISs can have sub-hierarchies of drivers for specific
types of resources. The structure of the hierarchy is not enforced by the framework
and can be built according to the specification of a given IS.
The actual Web service classes for each of the resource types extend the CRUD-
WebService class (e.g. EDB Equipment WS), thereby inheriting the full operational
skeleton, and implement the getDriver() method so that it produces an instance of a
SystemDriver subclass appropriate for the particular system-resource combination.
The framework structure has been designed to allow for various development
strategies depending on the type of a required Web service. There are three basic
development paths that are enabled by the framework:
• Rapid development of CRUD Web services for inclusion of new resources to the
integrated environment by adding new drivers
• Development of system specific operations not belonging to the CRUD set by
extending the SystemInteractingWebService
• Development of freeform REST Web services by extending the RESTWebService
Figure 12.8 illustrates the rapid development of CRUD Web services for accessing
equipment and document information in an EDB, and document in a DMS. Once the
first Web service has been completed, subsequent Web services require only minor
and well-encapsulated development efforts (Szepielak 2007).
The figure shows that each Web service comprises 6–7 code blocks from the
framework, only 1–2 of which need to be newly provided when the pool of Web
292 L. Hagge et al.
services is extended. Assuming the code blocks to be of equal size and complexity,
this would correspond to 14–33% of code needing to be provided, or an expected
average code reuse of at least 70%. This number can get much higher, if the
components which have to be developed are small compared to the others.
The different development paths offer developers great flexibility and allow using
only partial framework functionality, if required. This way, the potential framework
application extends beyond the described integration scenario and allows it to be
used for general software development purposes.
Application Examples
The integration approach and the REST Web-service framework have been de-
veloped and applied in the engineering data management domain at Deutsches
Elektronen-Synchrotron DESY in Hamburg, Germany. DESY is one of the world’s
leading centers for research at particle accelerators. DESY develops, builds and
operates particle accelerators, which are large scientific instruments, and conducts
basic research in a great variety of scientific fields, ranging from particle physics to
materials science and molecular biology.
This section describes three application examples of the presented REST WS
framework: Integrated information access across several information systems,
synchronization of information between existing systems, and building new appli-
cations on top of an existing environment. The examples involve some of DESY’s
key information systems, namely:
• The DESY Engineering Data Management System (EDMS), a customized
product lifecycle management (PLM) solution
• A combined Geographic Information System and Facility Management System
(GISFMS), built with various commercial components
• An Inventory Management System (IMS) based on a commercial IT Asset
Management System
DESY has developed a powerful portal which allows users to jointly and intuitively
search and navigate the GISFMS and EDMS. The portal provides information
about the DESY facilities (buildings and accelerators) through means of metadata
querying, hierarchy browsing or visual navigation using maps. The information
provided through the portal includes maps and building information from the
GISFMS, related with documents and 3D CAD models from the EDMS. REST Web
services are used for connecting to the GISFMS and EDMS, querying the systems,
and retrieving (lists of) objects.
12 A Framework for Rapid Development of REST Web Services for Integrating : : : 293
C R U D C R U D C R U D C R U D C R U D
Figure 12.9 illustrates the architecture of the portal application. The portal
provides location-centric information access, i.e. locations are the primary key to
information access. For this purpose, the portal provides a tree browser which
enables navigating from sites through buildings and floors to rooms, and a map
and plan viewer are provided. The Web components retrieve their data from the
GISFMS database using CRUD Web services.
The location information of the GISFMS is mirrored and synchronized in the
EDMS, where documentation, technical drawings and 3D models are processed
and related with their locations. CRUD Web services enable accessing locations,
documents, models etc. and traversing relations in the EDMS.
At the time of writing, the portal is already in operation for three years. It serves
information for a large-scale accelerator construction project and needs to adapt to
growing and changing requirements as the project progresses. So far, it has been
both very robust and flexible against changes: Additional information types, such as
e.g. 3D model viewing, have been added to the portal without impact on available
functionalities, and major software upgrades of the underlying information systems
have been successfully carried out without affecting the portal functionality.
Synchronizing Information
A Web-based information system had been developed based on EDMS and IMS
for coordinating the installation process in an accelerator project. It registered all
the components of the accelerators, provided work lists for the various technical
groups, tracked the installation progress, and provided a central information access
294 L. Hagge et al.
Component
Component
Documents
Inventory
Engineer
Inventory
component manage
Work
Lists
lists work lists
retrieve Coordinator
work lists manage
PETRA III retrieve documents
Project Member installation
status IMS EDMS
Document
manage manage manage
Manager components
work lists documents
Fig. 12.10 Using IMS and EDMS to support the installation process of a large facility
point for the installation status. The IMS was used for component and infrastructure
management and handling work lists, while the EDMS managed the technical
documentation of components. An integration component ensured consistency of
the information in both systems by propagating changes in one system to the other.
The integration component used the REST Web services framework to connect to
the systems, access and update objects, and trigger workflows.
Figure 12.10 summarizes the scenario. The different actors are working directly
with the ISs, as their roles are mapping 1:1 to one of the systems. Coordinators and
process managers use the rich native IMS or EDMS interfaces. The other project
workers, who are carrying out installation works in the accelerator facility, are able
to retrieve work lists and instructions through a Web-based reporting interface. An
integration application in the background ensures that information changes from
one system are propagated to the other: If a crucial information change is retrieved
from one system, an update Web service is called which propagates the change to
the other system.
The application has been realized in very short development time. It was built
on top of two information systems, which were in production and starting to show
an information overlap. According to the approach, the application has been non-
invasive, i.e. did not affect other projects that were also using the EDMS and/or IMS
for their activities.
The presented framework can be used to build new, specialized clients on top
of existing systems. As the DESY EDMS is a very large and complex system,
users often request lightweight and easy to use clients for special purposes. The
Web services are efficient building blocks for such applications by providing the
necessary basic functionalities for connecting, accessing and updating information.
Figure 12.11 illustrates a number of tools and applications, which have been built
on top of the DESY EDMS using the REST Web-services framework. They include
e.g. direct document searches and accesses from public project Web pages, bulk
12 A Framework for Rapid Development of REST Web Services for Integrating : : : 295
PLM Backbone
e.g. Parts & Document Mgt., Change / Configuration Mgt., Workflow Mgt.,
Collaboration, Communication and Visualization Tools, Access Control, …
Fig. 12.11 Special-purpose tools and applications on top of the DESY EDMS
loaders for batch upload of large amounts of files, and connectors for exchanging
and synchronizing data with other external databases and applications. Many of
these tools are requested at extremely short notice. With the framework in place,
such requests can usually be handled.
Summary
This chapter summarizes results and experience from implementing and operating
the described framework, and provides an outlook on a strategy for extending the
framework architecture for automating the integration of information systems.
Results
The first components of the presented framework are in stable in operation since
their initial deployment at DESY in 2005. Numerous extensions and applications
have been developed since then, increasing both the scope of operations and the
number of accessible information systems.
Figure 12.12 shows the byte code length for the different code blocks of
the framework as they have been measured for the initial set of Web services.
Figure 12.13 shows the increasing level of code reuse that has been observed as more
and more Web services have been developed (Szepielak 2007). The observed level
of reuse for all Web services operating in the DESY environment ranges between
83% (for the most complex Web services) and 98% (for the simplest Web services)
with an average of 93%. The calculations concern only the internal level of reuse
of the framework code itself. Taking into account external libraries used to build
the framework, as well as the fact that the Web services are designed to be used in
multiple applications, the average level of reuse exceeds 95%.
296 L. Hagge et al.
Web Service
WS Layer BCL
Functional Block
Request-Response Request-Response 11300
Processor Processor (RRP)
system interaction skeleton (sis) 1680
d e le t e ( d) 750
Fig. 12.12 Byte code length of code blocks in the initial set of Web services
Experience
Setting up the framework was experienced as a time consuming process, but the
initial time spent on building the framework resulted in faster and more efficient
development of the necessary Web services. The framework allows developing new
Web services for accessing further objects from underlying information systems
within a few days of work, thus assuring scalability for dynamic environments and
increasing integration. The framework also greatly eases the maintenance of existing
code.
12 A Framework for Rapid Development of REST Web Services for Integrating : : : 297
IMS (sd)
60
(not counting external libraries)
50
40
30
20
Operation
10 controllers
0
Consequtively developed web services
Fig. 12.13 Increasing level of code reuse observed during Web service development
The framework has been built completely from scratch, as at the time of the
project no mature enough frameworks were available. With the official JSR for
RESTful Web Services in place, JAX-RS (JSR311: JAX-RS 2009), a similar integra-
tion framework could be created based on one of the available JAX-RS implemen-
tations. Most of the functionality of the RESTWebService and CRUDWebService
classes could be taken directly from e.g. Sun’s reference implementation of JAX-
RS, Jersey. The other classes would still need to be custom-developed, as they are
specific to the presented integration framework and to date not available in any
generic REST framework.
Several of the underlying information systems have undergone major software
upgrades. As the framework successfully encapsulated those systems, no side
effects were observed on applications which were built using the Web services.
As newer versions of underlying ISs offer richer functionality, some of the Web
services may need to be extended to make this functionality also accessible to
other applications. In such cases, the REST CRUD paradigm has shown to be well-
suited for maintaining backward compatibility and thus avoid impacts on productive
environments.
Also the resource-centric approach has shown various advantages in the software
development process. The major advantage is that it reflects the business vocabulary,
which is particularly beneficial for developers, as they do not need to familiarize
with specific system APIs, but can work with a high-level intuitive information
access layer which is addressed in the same vocabulary as used in the business
itself. This greatly reduces the time until developers get productive and at the same
time improves the quality of the resulting software. For example, some of the tools
and applications described in “Building New Tools and Applications” have been
developed by new staff or students within the first month of their work.
298 L. Hagge et al.
Integration Application
e.g. Information Portal, Workflow Engine Ontology
WOIA middleware
synchronize
Execution execute Request Service Directory Ontology
Controller request Executor Engine models Engine
Request Registry
Transform. Execution Service
Module Ontology
Repository Directory
Management
Ctrl. System
Specification
Equipment
Data Sheet
Data Sheet
Subsystem
Document
Functional
Database
Operation
Technical
Technical
refers to
Process
Monitor
Manual
Design
Supply
Supply
Safety
Power
Power
uses ►
The analysis in “Integration Architecture” has shown that all integration applications
share two core functionalities: They need to be able to establish cross-system
relations, and to handle business objects which are fragmented over several ISs.
DESY has developed a dedicated integration application which generalizes these
capabilities. It shall act as a middleware which provides Web service registra-
tion, discovery, composition and execution capabilities. The architecture which
employs this middleware is called Web-Oriented Integration Architecture (WOIA)
(Szepielak 2007; Szepielak et al. 2010).
Figure 12.14 illustrates the WOIA middleware in the context of an integrated
environment as shown in Fig. 12.2: It consists of a registry and a request execution
module, which are both using the ontology to operate. Information systems register
within the registry as providers of resources which are defined in the ontology. Based
on the registration data, the request execution module allows consumers to directly
operate on resources without any knowledge about their providers, almost as if the
middleware itself would be providing all the Web services. The middleware has a
REST interface which allows the consumers to interact with it in the same way as
they would with any other REST service: Consumers send requests for required
resources directly to the middleware (the only part of the request that changes is the
host name), and the middleware will automatically identify the necessary providers,
12 A Framework for Rapid Development of REST Web Services for Integrating : : : 299
invoke the required Web services and compose the response, in case of distributed
resources by combining responses from several Web services. It also enriches the
response with links pointing to the related resources based on the information
retrieved from the ontology before the complete response is sent to the consumer.
Using such a generic middleware has the potential to reduce the integration effort
to defining an ontology and providing system and resource drivers for the available
information systems, while the rest of the required integration software would be
provided by the framework.
References
Boxall, M.A.S., Araban, S.: Interface Metrics for Reusability Analysis of Components. In
Proceedings of the 2004 Australian Software Engineering Conference (ASWEC’04). IEEE
Computer Society, Los Alamitors, CA, pp. 28–37, 2004
Brose, G., Vogel, A., Duddy, K.: JavaTM Programming with CORBATM: Advanced Techniques
for Building Distributed Applications. Wiley, NY, USA, 3rd edition 2001
Chang, M., He, J., Castro-Leon, E.: Service-Orientation in the Computing Infrastructure, In Pro-
ceedings of second IEEE International Symposium on Service-Oriented System Engineering
(SOSE’06), 2006
Curbera, F., Weerawarana, S., Leymann, F., Storey, T., Ferguson, D.F.: Web Services Platform Ar-
chitecture: SOAP, WSDL, WS-Policy, WS-Addressing, WS-BPEL, WS-Reliable Messaging,
and More. Prentice Hall PTR, Englewood, Cliffs, NJ 2005
Dietz, J.L.G.: Enterprise Ontology: Theory and Methodology. Springer, New York 2006
Erl, T.: Service-Oriented Architecture (SOA): Concepts, Technology, and Design. Prentice Hall
PTR, Upper Saddle River 2005
Erradi, A., Anand, S., Kulkarni, N.: Evaluation of Strategies for Integrating Legacy Applications
as Services in a Service Oriented Architecture. In Proceeding of IEEE International Conference
on Services Computing (SCC’06), 2006
Guber, T.R.: A Translation Approach to Portable Ontologz Specifications. Academic Press,
New York 1993
Gui, G., Scott, P.D.: Coupling and Cohesion Measures for Evaluation of Component Reusability.
In Proceedings of the 2006 International Workshop on Mining Software Repositories. ACM
Press, New York 2006
Howerton, J.T.: Service-Oriented Architecture and Web 2.0. IT Professional, vol. 9, no. 3,
pp. 62–64, May/Jun 2007
JSR311: JAX-RS: The JavaTM API for RESTful Web Services available at: http://jcp.org/en/jsr/
summary?id=311, accessed on June 08, 2011 (2009)
Kleppe, A., Warmer, J., Bast, W.: MDA Explained: The Model Driven Architecture: Practice and
Promise. Addison-Wesley Professional, Reading, MA, USA, 1st edition 2003
MDA Guide Version 1.0.1 available at: http://www.omg.org/cgi-bin/doc?omg/03-06-01.pdf, ac-
cessed on June 08, 2011 (2003)
Monson-Haefel, R., Chappell, D.: Java Message Service (O’Reilly Java Series). O’Reilly Media,
1st edition 2000
Musser, J. and O’Reilly Radar Team: Web 2.0 Principles and Best Practices. ISBN: 0–596–
52769–1 O’Reilly Radar 2006
Szepielak, D.: Web Oriented Integration Architecture for Semantic Integration of Information
Systems, PhD Thesis, Silesian University of Technology, Gliwice/DESY, Hamburg 2007
Szepielak, D., Tumidajewicz, P., Hagge, L.: Integrating Information Systems Using Web Oriented
Integration Architecture and RESTful Web Services, pp. 598–605, 6th World Congress on
Services 2010
Vinoski, S.: REST Eye for the SOA Guy, IEEE Internet Computing, vol. 11, no. 1, pp. 82–84, 2007
Part IV
Application Case Studies
Chapter 13
Managing Legacy Telco Data Using RESTful
Web Services
Introduction
D. Fuentes-Lorenzo ()
Carlos III University, Av. de la Universidad 30, 28911 Madrid, Spain
e-mail: [email protected]
To address these difficulties, tools are needed to ease the task to the company
staff. This is the main objective of the SEMNET project explained in this chapter,
which applies a new software architecture to the information systems of a telecom-
munications operator. In the context of this project, our objectives are two-fold.
First, the existing information has been accordingly transformed and structured
as Web resources to be easily available through RESTful Web services, which
can be accessed and manipulated by standard Web-based interfaces, through
common programming languages and a common protocol. Second, and to probe the
feasibility of RESTifying this existing information, the Web resources have been
implemented into a prototype applying a RESTful architecture, to take advantage of
scalability and both browsing and data searching facilities.
The remainder of the chapter is organized as follows. “Scenario and Information
Sources” covers the scenario where the Web technologies have been applied.
“Principles and Approach” explains the approach we have followed to RESTify
the legacy data involved. “Prototype” explains the basic implementation aspects
of the prototype and depicts some of its functional capabilities. “Related Work”
exposes some of the related work and, finally, “Conclusions” concludes with several
remarks.
We explain here the procedures and techniques used to accomplish the RESTifica-
tion of the legacy data involved.
Architectural Design
View
View
Application servers
HTML response
Index
XML Search
Controllers creation
response engine (batch)
Resource logic
Index
R R R R
Restify
Database
server
Legacy Legacy
Prototype Search
engine
The search engine is able to query the prototype information thanks to the
implicit Web services (RESTful Web services) the prototype itself implements; the
search engine receives information, in a batch process, by means of XML documents
with their associated XML schemas, which are then processed and indexed for
future user queries.
Data Representation
The nature (type) of the different columns is diverse. We can mainly find:
• Temporal information: Fields such as ini date, which store the timestamp of the
beginning of the SDR session.
• Connection information: The IP addresses of the origin and destination involved
in the SDR session are available in the ip address a and ip address b fields.
• Network parameters: These parameters represent, for example, the number
of kilobytes uploaded and downloaded by the customer, the time required to
establish the session or the average response delay to customer requests.
• Geolocation: There are fields which represent a text description of the geograph-
ical area where the customer is located.
Having this information into account, next subsections explain the main types of
resources that have been designed and referenced.
Simple Contents
Every information object (a client, a service, an SDR) is included here, where URLs
such as http://.../clients/[x], http://.../services/[y] and http://.../sdrs/[z] reference a single
client (also known as customer), service and SDR respectively. In this example, x, y
and z are the values of the columns which represent the primary keys of the Clients,
Services and SDRs database tables. These primary keys are integer numbers in the
legacy data used.
Figure 13.3 shows two examples on which URLs are assigned to each of the
simple resources involved; as can be seen, each simple resource is a record in a
database table.
Complex Contents
SDRS Table
identifier province ip_address_a service_id
SERVICES Table
identifier description
http://.../services/1
1 Movies purchase
http://.../services/2
2 Send email
http://.../sdrs/5
http://.../sdrs/6
Fig. 13.4 Mapping complex contents: From database tables to REST resources
A simple content can be related with complex contents. In the legacy data
used, a customer can have used one or several services and/or originated one
or several SDRs; an SDR is related to a service and two customers (origin
and destiny), etc. In this case, the relation between the resources is referred as
13 Managing Legacy Telco Data Using RESTful Web Services 309
SDRS Table
identifier province ip_address_a service_id
CLIENTS Table
ip_address phone_number
http://.../clients/10122168138 10.122.168.138 +34999888777
http://.../clients/10165143110 10.165.143.110 +34999666555
CLIENTS ( ip_address, … )
http://.../clients/10122168138/sdrs
Primary key
http://.../clients/.../sdrs/1
http://.../clients/.../sdrs/2
http://.../clients/.../sdrs/4
Foreign key
SDRS ( identifier, ini_date, service_id, vlan_interface, ip_address_a, … )
Fig. 13.5 Mapping relations: From foreign keys to filtered complex resources
http://../[set 1]/[x]/[set 2], where set 1 and set 2 can be any of the database tables
involved in any of these relations. x is the value of the primary key in table set 1,
representing the simple content.
In Fig. 13.5 we have an example of a relation transformed into another type
of complex resource. Given the set of resources of SDRs and clients, the relation
between a client and their SDRs can be obtained through the foreign key established
in their original database tables. To RESTify this relation, we just have to ask for the
complex resource (/sdrs) applied just for a single resource of a complex set (/clients).
In the example of the figure, the URL generated by this specific relation points to
the set of SDRs where the client is that with the identifier (ip address a column) with
value 10122168138 (/clients/10122168138).
As shown in the example, a unique resource can have more than one URL
which identifies it (the SDR with identifier 1 can be referred as http://.../sdrs/1 or as
http://.../clients/10122168138/sdrs/1). However, two different resources cannot have
the same URL.
310 D. Fuentes-Lorenzo et al.
SDRS Table
identifier province ip_address_a service_id
http://.../sdrs/queries
http://.../sdrs/queries/identifier
http://.../sdrs/queries/identifier/1
http://.../sdrs/queries/identifier/2
http://.../sdrs/queries/identifier/3
http://.../sdrs/queries/identifier/4
http://.../sdrs/queries/province
http://.../sdrs/queries/ip_address_a
http://.../sdrs/queries/service_id
Fig. 13.6 Mapping definition of queries: From possible properties and values to functions
Functions
SDRS Table
identifier province ip_address_a service_id
Fig. 13.7 Mapping execution queries: From properties and values to functions
Prototype
Implementation Environment
SERVICES Table
identifier description
http://.../services/1
1 Movies purchase
http://.../services/2
2 Send email
http://.../services/1/graphics
http://.../services/1/graphics/2009
http://.../services/1/graphics/2009/10
http://.../services/1/graphics/2009/10/23
http://.../services/1/graphics/2009/10/24
http://.../services/1/graphics/2009/10/25
http://.../services/1/graphics/2009/11
http://.../services/1/graphics/2009/12
http://.../services/1/graphics/2010
In this case, the application has been built on a Rails (Thomas et al. 2005)
environment, upon a Web server. Rails is a framework for the development of Web
applications. Two of the most important benefits, crucial to the selection of Rails,
are the following:
• Rails implements the MVC pattern automatically.
• Rails includes an entire structure to generate RESTful applications and design
RESTful resources in a semi-automatic way.
Ruby (Flanagan and Matsumoto 2008) has been the programming language chosen
for the implementation. Ruby, in addition to being powerful and simple, is also
portable, capable of being executed indistinctively on most common platforms
including Linux, Windows, Mac, etc.
Figure 13.9 shows the basic implementation flow for a couple of related resource
types, the SDR resource collection and the Client collection. After designing the
resources needed, and with the help of the Rails model layer, the resources designed
are implemented in the form of typical Rails model classes, called ActiveRecord
(AR) classes. As can be seen in the figure, an AR object can have relation with
another AR object. In the example presented, an SDR is originated by a client, and
a client can have generated many SDRs.
Every resource is ruled by a controller with simple CRUD functionality (Create,
Read, Update and Delete actions). Every controller is also associated with a view to
present the data to the user. The routes the controllers can generate or response to
are defined in a configuration file. As the resources are related, the controller of one
resource can ask for information to the related resource.
13 Managing Legacy Telco Data Using RESTful Web Services 313
Design Implementation
Table SDRs SDR
Functional Aspects
This section shows the main functionalities offered by the prototype, including the
search engine. These main functionalities are related with browsing and searching
and can be accessed through the GET method of the HTTP protocol.
Browsing
The access to the SEMNET prototype can be accomplished with any HTTP client
interface, such as a Web browser. The format in which the requests (and answers)
can be made (and received) can be either HTML or XML, although more formats
may be added in a simple way.
Users can mainly browse the stored information, which is basically the
following:
• Transactions and service-detailed records (that is, the SDRs)
• Requested services on the IPTV scenario (or just services)
• Customers, which represent entities who begin or received the event of a service.
Each entity can be a person or a server
The navigation is performed through hyperlinks, without filling in any form to
indicate the search parameters or requests, as all of the needed data for the facilities
has a unique URL which identifies it. Figure 13.10 shows several screenshots of the
homepage or main menu (left), a statistical graph of the use of a particular service
(middle) and a resource collection, the list of SDRs (right).
The user can navigate directly to each of these sets of data from either the
homepage or from each of every point of information through hyperlinks, due to the
fact that the different resources are interrelated and all the parameters needed for a
request are in the hyperlinks themselves. For example, the Web page that displays
an SDR resource can link to the resource representing the customer who generated
such SDR. As shown in Fig. 13.11, step 1, from the list of SDRs, user can see all the
details of a certain SDR of that collection.
314 D. Fuentes-Lorenzo et al.
certain date, or/and the origin was located in a specific region, and so on. To set
an example, as shown in Fig. 13.11, step 2, users can navigate from one SDR to
a list of the SDRs with VALLADOLID (a Spanish city) as the origin, by clicking
the hyperlink of the property desc iporigen (the province where the SDR was
originated).
Queries information is encoded in the URLs, following REST conventions. This
facilitates future searches made by human users, who can also type the query
elements directly in the Web browser, or save the hyperlinks as bookmarks for
future use.
Searching
The user can also access to SEMNET information through a search engine
(Fig. 13.12). This engine incorporates the following components:
• A page-crawler module based on the Nutch (http://lucene.apache.org/nutch/) tool
• A page-indexer module based on Apache Lucene (http://lucene.apache.org/)
• A Google-like interface with a traditional free text box
The availability of the SEMNET information as RESTful resources with well-
known URLs facilitates the incorporation of this search system, allowing the user to
search information in a simple, versatile and friendly way.
316 D. Fuentes-Lorenzo et al.
Related Work
Even though it is difficult to find related proposals in the same scenario or with
a related use case as the one presented in this chapter, there are initiatives that
already apply RESTful architectures in companies for a better addressability of their
resources.
One example is Dogear (Millen et al. 2006), an enterprise-scale social bookmark-
ing system. They also provide design principles referring to online identity, privacy,
information discovery and service extensibility.
Practical projects are also developed in Scofield (2008), a book devoted to
developers who use Rails regularly for advanced sites and applications.
In Schmidt (2006) or Vinoski (2006), authors focus on the integration of
several technologies, including REST, and languages like Ruby to develop the
new enterprise applications, embracing the idea of easiness and efficiency these
technologies bring to development and maintenance.
In Rosenberg et al. (2008), authors explain the possibility of data integration and
composition with RESTful services, a task which may be considered very powerful
in the SEMNET context, enabling the possibility of integrate data from different
services or network components through Web mashups.
Finally, in Kumaran et al. (2007), authors present the design of a platform for
service management with REST. Even though the services they refer to are applied
mostly to commerce, they can be extrapolated to any other area.
Conclusions
In this chapter, we have presented the steps to transform the legacy data of a
telecom company into well-defined Web resources. All this actual telco information,
obtained from one of its distributed network and service monitoring facilities, has
been conveniently transformed and structured to be available through RESTful Web
services. A proof of concept to validate the approach has also been conducted, in
the form of a Web-based application, the SEMNET prototype. This Web application
has been implemented to exploit all the previously processed information, allowing
different indexing and searching operations over the Web resources obtained.
The model adopted in SEMNET facilitates the recovery, clustering and data
mining tasks, simplifying the information integration and dissemination in other
systems, and allowing the use of collaborative features (annotation, sharing of
13 Managing Legacy Telco Data Using RESTful Web Services 317
bookmarks, reports, etc.) based on Web resources. In addition, this model allows
using standard search engines to locate relevant information in a quickly, adaptable
and simple way, as it is done on the Internet.
The approach adopted can be easily extrapolated to legacy data of any different
business sector. The results also raise a number of tangible benefits to users of
management tools, demonstrating that the following advantages applying RESTful
techniques can be obtained:
• Web access to information management systems
• Standardising of the information systems interfaces
• Reduction in training resulting from the familiarity with the browsing and
searching environment
• Integration into customized interfaces
We have identified some limitations in the potential generalization of this prototype
to other information systems; these limitations will allow opening new opportunities
within the same spirit of innovation:
• Information persistence: Apart from traditional databases, further techniques for
information storage may be needed, to provide a possible expansion of data
sources.
• Generalization of network data: There is a need to explore automatic or semi-
automatic techniques for the creation of the Web-resources’ layers, to avoid the
need to perform ad-hoc implementation.
• Knowledge extraction, formalization and exploitation: Knowledge management
has not been addressed, but the prototype provides the basis for encouraging this
knowledge flow, such as taking advantage of the user experience through search
analysis, or facilitating the task of analysing shared information.
References
Flanagan, D., & Matsumoto, Y. (2008). The Ruby Programming Language O’Reilly.
Kumaran, S., Li, Y., & Dhoolia, P. (2007). The deep structure of service management. Paper
presented at the ICEBE ‘07: Proceedings of the IEEE International Conference on e-Business
Engineering, 62–70.
Larman, C. (2005). Applying UML and Patterns: An Introduction to Object-oriented Analysis and
Design and Iterative Development (3rd ed.). Upper Saddle River, N.J: Prentice Hall PTR.
Millen, D. R., Feinberg, J., & Kerr, B. (2006). Dogear: social bookmarking in the enterprise.
Paper presented at the CHI ‘06: Proceedings of the SIGCHI Conference on Human Factors
in Computing Systems, Montréal, Canada,111–120.
Reenskaug, T. (1979). The Original MVC Reports. Oslo: T. Reenskaug.
Rosenberg, F., Curbera, F., Duftler, M. J., & Khalaf, R. (2008). Composing RESTful services and
collaborative workflows: a lightweight approach. IEEE Internet Computing, 12(5), 24–31.
Schmidt, M. (2006). Enterprise Integration with Ruby. Raleigh, N.C: Pragmatic Bookshelf.
Scofield, B. (2008). Practical REST on Rails 2 Projects (Practical Projects) APress.
Thomas, D., Heinemeier Hansson, D., & Breedt, L. (2005). Agile Web Development with Rails:
A Pragmatic Guide. Raleigh, N.C: The Pragmatic Bookshelf.
Vinoski, S. (2006), Enterprise integration with ruby. IEEE Internet Computing, 10, 91–93.
Chapter 14
Case Study on the Use of REST Architectural
Principles for Scientific Analysis:
CAMERA – Community Cyberinfrastructure
for Advanced Microbial Ecology Research
and Analysis
Abstract The advent of Grid (and by extension Cloud) Computing along with
Service Orientated Architecture (SOA) principles have lead to a fundamental shift
in the development of end-user application environments. In the scientific domain,
this loosely coupled, multi-tiered software architecture has been quickly adopted as
raw data sizes have rapidly grown to a point where typical user workstations can no
longer perform the necessary computational and data-intensive analyses. A current
challenge facing the design and development of SOA involves the management
and maintenance of many loosely coupled service components. As with many large
applications, “integration” is equally important as “coding”. A resource orientated
architecture style serves well in addressing these challenges. Here we present
the CAMERA (Community Cyberinfrastructure for Advanced Microbial Ecology
Research and Analysis) project as a case study for a SOA in scientific research
environments.
Introduction
The advent of Grid (and by extension Cloud) Computing along with Service
Oriented Architecture (SOA) principles have lead to a fundamental shift in the
development of end-user application environments. No longer do stand-alone
applications need to be installed on client workstations. Rather, user applications are
now inherently lightweight – relying on remote service calls to “do the work”. In the
scientific domain, this loosely coupled, multi-tiered software architecture has been
quickly adopted as raw data sizes have rapidly grown to a point where typical user
workstations can no longer perform the necessary computational and data-intensive
analyses.
A current challenge facing the design and development of SOA involves the
management and maintenance of many loosely coupled service components. As
with many large applications, “integration” is equally important as “coding”. With
individual application services written by different developers (often in different
programming languages), strict design principles must be followed to ensure a
reliable and robust user experience. These principles seek to result in an environment
where the user experience appears to be unified, despite a multitude of services
working “behind the scenes”.
A resource oriented architecture style serves well in addressing these challenges.
Here we present the CAMERA (Community Cyberinfrastructure for Advanced
Microbial Ecology Research and Analysis) project as a case study for an SOA in
scientific research environments. Specifically, CAMERA is fundamentally based on
a collection of REST services. These services are linked together by a scientific
workflow environment (Kepler) and presented to end-users in a unified environment
geared towards scientific genomic researchers (Sun et al. 2010).
CAMERA
The primary goal of the CAMERA Project is to provide a resource for the scientific
genomic community to perform computational and data intensive analysis that
would otherwise not be possible with the computational restraints of individual
laboratories. These analysis range from data rich with little computational “horse-
power” to compute intensive on relatively small amounts of data.
In addition to these computational and data “hardware” requirements, we
designed CAMERA to meet two unique needs of the community:
1. User Driven Analysis
CAMERA is a unique resource in that it allows user to design and launch their
own custom analysis using CAMERA resources. From a software development
perspective this means that services and workflows are developed not only by
CAMERA but also by the community at large. Because development does not
occur in a centralized, controlled environment, CAMERA’s infrastructure must
be both relatively simple and well documented. REST services play critical roles
as the limited scope of the constrained create, read, update, and delete (CRUD)
interface provides an adequate boundary condition for service behavior.
2. Provenance
Scientific research methods require a full record of transformations applied
to data. The adoption of an SOA can make record keeping challenging as
many services may act upon a single dataset. A strict separation of concerns
(SoC) coupled with REST services makes full provenance recording possible
14 Case Study on the Use of REST Architectural Principles for Scientific Analysis... 321
The layered and modular CAMERA software architecture, as illustrated in Fig. 14.1,
is designed to serve two purposes: (1) to provide an adequate SoC for different sys-
tem components and (2) to allow external scientific developers to create workflows
that can fully utilize CAMERA software and hardware resources.
The elements and techniques readily incorporated into CAMERA’s architec-
ture include an effective, flexible and intuitive user interface that facilitates and
enhances the process of collaborative scientific discovery for domain scientists –
accomplished through an end-user interface model that blends both Web and
traditional desktop application environments. Primary user interaction is provided
via a centralized Web Portal interface. Under the Portal layer are the data and
workflow management components to assist with assembly of components into
useful and more complex scientific discovery tools. The CAMERA infrastructure
currently employs the Kepler workflow system, but it is built for extensions to accept
workflows from other workflow systems.
322 A.W. Lin et al.
Design Principles
Scalability
Genomic data is growing at an exponential rate. Already, data sizes have out-grown
capabilities of standard desktop workstations. User applications now heavily rely on
Cloud-based services to perform much of the work. One of the advantages of SOA is
how it manages scale. Because CAMERA’s core application services are state-less
we can, based on demand, provision more instances of the services to be used.
Another aspect of scalability is what we call “developer scalability”. Unlike
many large-scale projects, the analysis tools are not all developed in-house. Rather,
the scientific community contributes a significant portion of the tools. This is where
CAMERA’s use of REST is most significant.
Most genomic tools were developed prior to the advent of Web services. To
integrate them into CAMERA, the first task is to develop a service-based interface.
Because REST follows a CRUD interface model, it is simpler for applications
developers to add this interface. Even with a simple REST interface, CAMERA
further specifies the need for a Camera Service Description Language (CSDL)
markup to accompany each service (see pages 324 and 327 for a full description
of CSDL and how it is utilized in CAMERA).
Modularity
The importance of modularity increases with the number of components within the
SOA. In CAMERA each service is a self-contained component that is state-less,
independent and otherwise unaware of other services. This allows us to develop
services independently from one another. This adds parallelism from both the
computational scalability and development perspective.
Language Independence
Within the CAMERA SOA, client applications use Web services to communicate
with each other. While the Web service protocol is an industry standard that is
language independent, we have found that in practice it is difficult to have multiple
clients and services of multiple languages work together.
In single language environments such as J2EE, SOAP-based services can be an
excellent choice as the J2EE framework provides consistency. In multi-language
environments, however, we have found the impedance mismatch between SOAP
implementation becomes a burden.
Like many large infrastructure projects, however, CAMERA developers spend as
much time integrating code as they do developing new code. CAMERA integrates
code from a myriad of sources encompassing platforms varying from application
server JBoss to simple Perl and PHP scripts. To maintain optimal language
independence, the limited CRUD operation of REST was adopted.
324 A.W. Lin et al.
Within CAMERA, core applications and data are accessed via REST Web services.
Principally, CAMERA utilizes RESTful principles to allow the incorporation of
software tools for refinement and analysis of community data into workflows.
Wrapping community tools for CAMERA takes three main steps:
• Expose low level bioinformatics tools, e.g., NCBI BLAST, as services that are
reachable via a unique URI.
• Develop “applications/process workflows” to link together and activate multiple
resources via Kepler.
• Deploy portal components to manage multiple “applications” (or to interact with
a single resource) and to manage user/application state.
The first step in the process of reengineering these bioinformatics tools into full-
fledged workflow elements is the creation of a simple programmatic interface (API)
for every tool. Specifically, we expose each bioinformatics tool as HTTP address-
able Uniform Resource Indicators (URIs) and parameters so that the application
is transported through a simple XML-based data exchange format. This process
assumes that CAMERA 2.0 resource services are atomic and stateless. State and
session management of their integration in processes are managed by the Kepler
workflows and Portal interfaces that are built upon these resource services. While
these resources have initially been used only internal to CAMERA as part of the
greater infrastructure, they are also being developed towards a goal of enabling third
party developers to access and utilize these resources within their own applications.
<?xml version="1.0"?>
<CameraWebApp xmlns:camera="http://camera.calit2.net/webapp/wadl">
<resources base uri="http://132.239.131.106/camera/rohwer/v1.1/">
<resource name="circonspect">
<method name="POST">
<request>
<parameter name="u" type="int"
descriptive name="Discard Size" />
<parameter name="v" type="int"
descriptive name="Trim Size" />
...
</request>
<response>
<representation mediaType="text/xml" />
</response>
</method>
</resource>
</resources>
</CameraWebApp>
14 Case Study on the Use of REST Architectural Principles for Scientific Analysis... 325
Workflows
domain specific programs. The use of REST services in conjunction with the KPR
is critical to the simplicity and robustness of the provenance design.
While a full discussion of the KPR is outside the scope of this chapter, it is a
critical component of the CAMERA infrastructure as REST services do not contain
and record state nor status information. As a result, we rely on workflows and the
KPR to capture all necessary status and other provenance information.
REST Actor
The REST service actor, works with any REST service given that user has a
prior knowledge of parameters and files needed to be passed to the service for it
to execute the underlying tool. In Fig. 14.2, we configure the REST Actor for a
simple service from Amazon Web Services (http://developer.amazonwebservices.
com/connect/entry.jspa).
Figure 14.2a demonstrates the REST actor being configured for a Get method, a
delimiter (comma in this case) is provided to indentify the different input parame-
ters. From the workflow canvas (Fig. 14.1b) we see two parameters (ExternaID and
ref) passed to the service as parameters.
14 Case Study on the Use of REST Architectural Principles for Scientific Analysis... 327
The REST service actor described above assumes that user already knows what
input/file parameters or the service. As previously described (page 323), CAMERA
services are described by the CSDL. It contains complete information about the
serviceSiteURL, methodType, and the input/file parameters. We have a specific
CAMERARESTService actor, which makes use of CSDL file for customization
purposes.
As shown in Fig. 14.3, double clicking on the CAMERARESTService actor
(Fig. 14.3a) opens up a slightly different a dialog box. Here we provide a URL to
the CSDL file (also notice that the delimiter option is no longer available). With the
CSDL, the actor automatically configures itself (Fig. 14.3b).
If we now look at the Actor configuration post customization (Fig. 14.3c) we
see that that the “serviceSiteURL” and “methodType” parameter are also auto-
configured just like other parameters for the service.
Launching Workflows
At the heart of CAMERA are Kepler workflows and the services called by those
workflows. Workflows are created from a dedicated design interface. After creation
they are saved in a XML-formatted Modeling Markup Language (MoML). This
MoML can then be uploaded (via the Portal) to run on CAMERA resources.
To satisfy the processing needs of these services and workflows, CAMERA has
its own compute cluster. This section describes the CAMERA cluster along with
how jobs are run on the cluster.
The CAMERA compute cluster currently consists of 103 Dell 1950s with two
dual core 2.33 GHz Intel Xeon processors and between 4 and 16 gigabytes ram
and 8 Dell 1935s with two quad core AMD Opteron 2356 processors with 16
gigabytes of ram. This cluster is backed by 18 terabytes of storage on a network
file system hosted by a Sun X4500 server. The compute cluster uses ROCKS (www.
rocksclusters.org) to manage the cluster, ganglia for statistics, and Intermapper for
monitoring. Sun Grid Engine (SGE, www.gridengine.sunsource.net) installation is
used to run jobs on the cluster.
Below is a table showing compute hours consumed by processing for the summer
of 2010:
Number compute
Month–Year hours consumed
July-2010 99,172
August-2010 88,840
September-2010 96,349
328 A.W. Lin et al.
Challenges
In design of an SOA, RESTful or not, comes with challenges that are different from
stand-alone applications. With a multi-layered architecture, a central challenge is
killing jobs that may have processes that span across all layers. In addition, SOA
adds challenges to proper testing and deployment of applications, both due to the
sheer number of components that must be managed and to the fact that services
utilized that may be outside of our immediate purview.
We also had to consider the pit falls of SOA, in particular with respect to computing
and find ways to address them. From the CAMERA Portal, each job launch starts a
specific workflow based on the user’s selection of input parameters and files. Most
genomic data (e.g., fasta file) consists of tens to hundreds of thousands of sequences,
from which a typical workflow computation lasts anywhere from several hours to
several days.
With such computational intensity, it is imperative that CAMERA allows users to
terminate jobs. As with most SOA, it is not enough to simply terminate the “parent”
process (in our case the workflow) as that in most cases does not also terminate the
330 A.W. Lin et al.
@org.junit.Test
public void testSubmitWorkflowJobWithNullArg() throws Exception {
try {
keplerSGEClient k = KeplerSGEClient.getInstance();
Catch(IllegalArgumentException ex){
//Caught exception and verify message is correct
assertTrue(ex.getMessage().contains(‘‘Null WorkflowTask’’));
}
}
The Perl tests below verify that get and set methods in the User class work
correctly.
@org.junit.Test
public void testGetExeStatusWithValidJob() throws Exception {
334 A.W. Lin et al.
Mock objects are great for enabling unit tests to be written that exercise code
which call external services and systems, but from time to time the behavior of the
mock object has not matched that of the service resulting in a failure of the system
during the integration step.
The next level of testing employed at CAMERA is known as system tests, or
tests that exercise aspects of the entire system. For systems and services this testing
is done by including testing programs that are deployed along with the application
to the various environments. These programs call the services and systems the same
way a user would and include code to verify correct operation.
One example of this is with the Kepler workflow system tests, which are written
in Java using Junit and are invoked by an ant build target in the workflow build
source tree. Below is an example of invoking a system test on the Blastn workflow
where the unit test is invoking the workflow the same way a user would if logged
into the system.
BUILD SUCCESSFUL
Total time: 3 minutes 11 seconds
While technically this isn’t a total system test as the workflow being tested is
local to the source tree, the services and processing are on the appropriate target
environment (development, stage, or production).
The system tests have proven to be very valuable in checking system integrity
and as an automated way to check new releases, but issues have arisen. One issue
is these tests can take several hours to completely run. Another issue is they require
access to the cluster which is quite busy and necessitates putting on hold real user
jobs. It should also be noted these system tests do NOT test the user interface portion
of the code base which is left to manual testing at time of release.
Fully testing SOA such as CAMERA that contains both internal and externally
developed software is an ongoing challenge. While there will likely always be
discrepancies between tests and reality, and impact of testing on production, the
benefits have outweighed the costs and appear to have improved the quality of the
system.
Services and applications that comprise of the CAMERA system each have their
own source tree and build systems and are owned by several different development
groups within CAMERA. In addition, some of the applications predate the CAM-
ERA group and already have preset configurations for setup and deployment. It is
in this context that a deployment system needed to be developed.
Rather than attempt to force all these diverse projects into a single code base
it was decided to leave everything where it was, but to setup a consistent way of
configuration and deployment for each application and to create a master build and
deploy project that could checkout, build, and deploy the entire software stack. This
master project is known, for lack of a better name, as camera build and deploy.
Figure 14.6 summarizes what camera build and deploy does.
The entire deployment system is based upon a few simple premises. The first
premise is that each server to host one or more applications must be “provisioned”
with proper system software and configuration to support the application. Second,
each application must be able to consume a properties file that defines all config-
urable aspects of the application including where to deploy. Third, each application
must be able to deploy itself via scp and ssh to its target host. This includes making
calls to stop and start appropriate services.
The camera build and deploy project contains logic in its build file to checkout
all these applications along with a properties file that merely lists properties
files for all the applications it is to deploy. Below is a exerpt from the cam-
era build and deploy properties file.
336 A.W. Lin et al.
cvs co camera_build_and_deploy
cd camera_build_and_deploy
ant -Dproperties.file=properties/prod.properties deploy
Invoking camera build and deploy above would invoke a command similar to the
one below for every application the camera software stack. In the example below,
the blast service and Web interface is built and deployed to environment defined in
prod.properties file:
cvs co camera
cd camera
ant -D properties.file=config/prod.properties -f build-all.xml
deploy-all
modify values in multiple property files. Even this issue has been minor considering
the number of applications that have to be deployed that make up the CAMERA
software stack.
Discussion
Acknowledgements This work is supported by the Gordon and Betty Moore Foundation.
References
Deelman, E., Gannon, D., Shields, M. and Taylor, I. (2009) Workflow and e-science: an overview
of workflow system features and capabilities. FGCS, 25, 528–540.
Ludaescher, B., Altintas, I., Berkley, C., Higgins, D., Jaeger, E., Jones, M., Lee, E.A., Tao, J. and
Zhao, Y. (2006) Scientific workflow management and the Kepler system. Concurrency Comput.
Pract. Exp., 18, 1039–1065.
Sun, S., Chen, J., Li, W., Altintas, I., Lin, A., Peltier, S., Stocks, K., Allen, E.E., Ellisman,
M., Grethe, J., and Wooley, J. (2010) Community cyberinfrastructure for advanced micro-
bial ecology research and analysis: the CAMERA resource. Nucl. Acids Res., 1–6. doi:
10.1093/nar/gkq1102
Chapter 15
Practical REST in Data-centric Business
Applications: The Case of Cofidis Hispania
Thank you very much to Esther Vidal, Jordi Albert, Albert Espelt
and Oriol Garcia for their commitment to this project. Great
job!
In a story that is too common in the financial sector, Cofidis Hispania has relied for
decades in its legacy mainframe systems for day-to-day business. In this market,
applications tend to be heavily data-centric, relying in central databases to store
information about customers, contracts, accounts payable, and interaction with other
financial institutions. All this data must be readily available to maintain a growing
set of critical indicators about credit, debt, risk and profitability.
In 2005, Cofidis was running most of its operation through an application suite
residing in the mainframe and accessed through terminal emulators from commodity
PCs from all areas of the company, including the Call Center – the heart of the
operation and the customer-facing side of the business. The legacy application suite
J. Fernandez ()
Esilog Consulting, S.L., Aribau 112, Barcelona, Spain
e-mail: [email protected]
was responsive and reliable, but imposed a steep learning curve on all new hires,
requiring extensive training and with a low margin for human error. Moreover, the
organization was facing a drying supply of skilled COBOL programmers, which
translated in long development times even for the tiniest maintenance changes,
making it harder to create new software modules to support new products and
maintain the lead in a growing market. As consultants, the challenge was to
provide Cofidis with an agile development environment that allowed the company
to leverage its IT resources for competitive advantage.
The suggested approach was to create an interface layer to phase out the legacy
systems in favor of the Java Enterprise platform, so new modules could be built in a
matter of weeks instead of months, using skills readily available from a rich pool of
consulting firms with a java-centric software development practice.
Building a web-based corporate software platform is a challenge that needs
to take into account the needs of different stakeholders besides those of the end
users: those of the executives, project leaders, system administrators and software
development teams just to name a few.
The stakeholders imposed a set of constraints that created an interesting chal-
lenge from the software architecture standpoint. Some of the most interesting were:
• Adopting a strict, ACID1 – compliant transaction approach at all levels as a
definitive business requirement. In a data-centric organization it is essential to
maintain a reliable database at all times.
• It was necessary to take into account the integration points with diverse external
systems – the mainframe during the transition period, all PBX2 and CTI3
infrastructure, ERP4 and accounting systems, and so on.
• Build Web-based applications with a level of responsiveness that compares
favorably with the (then) current user experience, which was based on using a
terminal emulator to establish telnet sessions to the mainframe.
• Make the best effort to mitigate the impact of the transition from an environment
that required mastering a single programming language (COBOL) to another
that required knowledge of several languages (Java, Javascript) and markup
languages (XHTML, XML).
• Define a common software architecture that provides guidelines to the efforts of
software developers so that several software providers could participate in the
1
Atomicity, consistency, isolation, durability (ACID) is a set of properties that guarantee database
transactions are processed reliably.
2
A private branch exchange (PBX) is a telephone exchange that serves a particular business or
office, as opposed to one that a common carrier or telephone company operates for many businesses
or for the general public.
3
Computer telephony integration, also called computer–telephone integration or CTI, is a technol-
ogy that allows interactions on a telephone and a computer to be integrated or co-ordinated.
4
An Enterprise Resource Planning (ERP) system is an integrated computer-based application used
to manage internal and external resources, including tangible assets, financial resources, materials,
and human resources.
15 Practical REST in Data-centric Business Applications... 341
building of the platform while keeping coherence among developments from the
architecture standpoint.
• Provide a reasonable migration path for legacy systems, so live with new
developments while maintaining consistency of data.
• Achieve maximum business logic code reuse among web, batch or rich client
applications – batch processing is a staple in most financial institutions.
• Switching client tier technology should be supported by the architecture. Aim
for a web-based client tier in the first phase, but different client tier presentation
technologies should be explored, including RIA and rich desktop client (such as
Eclipse RCP).
• Call-center employees usually work simultaneously with two or more customers.
A single employee will use more than one browser instance at any given time.
• Scalability is a principal concern. There is high concurrency and high peak loads.
Besides, the business is growing rapidly and it is expected that this same software
platform would serve other countries.
Besides the explicit restrictions manifested by the stakeholders, we need to
keep in mind other highly relevant implicit restrictions. The most obvious are
those related with moving from a local software development context – COBOL
programs running in a mainframe – to a distributed programming environment such
as an Intranet built using the same technologies used for the World Wide Web.
And moving from a local environment to a distributed programming environment
presents a particular set of challenges as identified by Waldo et al. (1994): latency,
a different model of memory access, and issues of concurrency and partial failures.
One of the ideas that we try to inseminate into our software development teams
is that – in the great majority of cases – we won’t be the first entity to encounter
a given software development challenge, so it is always convenient to check out
if there is an existing solution to the particular problem we are facing. The same
concept applies from a software architecture standpoint: we saw clearly that in
order to guarantee the coherence among the multiple development modules, all of
them should exhibit certain architectural qualities that captured the aforementioned
requirements. It is very likely that other persons have faced this same challenge, so
we should take advantage of all existing knowledge. We have at our disposal many
forms of reutilization at the architecture level, including Domain Specific Software
Architectures, Architectural Patterns, Architectural Styles and Design Patterns.
The reader may be familiar with the concept of Design Pattern as presented by
Gamma et al. (1994). Design patterns offer excellent design solutions in the context
of object-oriented programming, but this kind of solutions do not apply to systems
design at the enterprise level. At this scale we will find Domain-Specific Software
342 J. Fernandez and J. Rodriguez
The REST architectural style consists in a set of constraints that, when applied to a
software system, some beneficial qualities arise. This section will show the reader
how every restriction of the REST architectural style addressed some of the most
important challenges of this project.
Client–Server
Stateless
In our opinion, avoiding to maintain state in the server side is a crucial element for
the success of any web-centric software development project. When we maintain
state in the server, we open the door to a multitude of problems that will show up
progressively through the project, either during development or testing in a best-case
scenario, but the nastier bugs will linger in the dark, waiting to show up in a critical
production phase. An entire legion of developers has been raised using (and abusing)
the session object that practically every web development framework leaves within
their reach. Using this object to store the conversational state of a web interaction is
an error, plain and simple. This does not mean that there are no legitimate uses for
the session object – caching data for a specific user is a perfectly honorable use of
this resource.
5
We will see in “Uniform Interface” how the Uniform Interface constraint plays a key role here.
344 J. Fernandez and J. Rodriguez
Fig. 15.1 CPU and Heap memory usage for a stateless RESTful application under 350 stressing
request threads. After a transient period the memory usage stabilizes to around 250 Mbytes
The stateless constraint means that each request from client to server must
contain all of the information necessary to understand the request, and cannot take
advantage of any stored context on the server. Session state is, therefore kept,
entirely on the client. In the moment that the server remembers the state of the
session we are binding the client – a particular instance of a web browser – to that
server. If the server crashes and the client is redirected to a different server, the
request will fail because the state of that particular conversation is missing in the
new server. Yes, we are aware of the existence of session clusters in JEE application
servers, but why would anyone want to increment the complexity of a system when
there is a simpler approach to the same means through stateless interactions?
Another typical problem related to keeping state in the server is when the user
decides to open a new window in the same instance of the web browser. Both
windows interact with the application in the context of the same session. This is a
subtle situation that only complicates session management and is highly conductive
to error.
Let us imagine for a moment that a rookie developer decides to store in the server-
side session object the customer ID of the current customer. Do you remember the
aforementioned requirement of letting a user working with several customers at
once? This situation involves having several windows open at once, each presenting
data for a different customer. Keeping the customer information in the session object
makes it impossible to work reliably with several customers at once. But if we keep
the state in the client – using a hidden field for the customer ID, for instance – the
problem disappears.
There is a noticeable effect in terms of scalability for the stateless quality of the
REST architectural style. Keeping state in the client allows the server to free its
resources faster, since resource utilization is constrained to a single HTTP request.
In practice, having a stateless application has brought benefits along several lines.
First, the usage of heap memory in the server tends to stabilize over time for a
given number of users. Figure 15.1 shows the CPU and memory usage for a 350
15 Practical REST in Data-centric Business Applications... 345
request threads stressing the server without waiting intervals (we are then simulating
much more than 350 users). After a short transient period the memory usage settles
to around 250 MB in heap space.6 Second, by avoiding the usage of the session
and application scopes we gain in development simplicity, as there is no need to
synchronize concurrent access to shared resources. Third, we avoid all problems
associated to a user that initiates a session in a different browser but using the same
credentials.
Cache
6
Not maintaining server-side session state is a key factor in the low memory usage footprint, but
the intense use of singleton objects (via the Spring Framework) is of great help here as well.
346 J. Fernandez and J. Rodriguez
Fig. 15.2 The first time we GET an XHTML representation it takes 135 ms for the browser to
obtain a response as we can see in the Firebug console log
Fig. 15.3 The second time we GET an XHTML representation for the same resource with the
appropriate cache headers the application “knows” that the representation has not changed since
it was last requested, the JSP is not processed and a 304 response code is returned to the client
(a web browser in this case). It now takes 20 ms for the browser to obtain a response (15% time as
compared with 135 ms)
15 Practical REST in Data-centric Business Applications... 347
The reference architecture mandates that, whenever possible, all data obtained
from the database or from a business service is cached by default. Of course, the
web presentation layer takes advantage of this caching. But we must not forget that
the batch processes will take advantage of this cache as well. An innocent-looking
database query with a 5 ms cost that could be cached but is not can be overseen in
a web application. But that same overhead during a hypothetical batch process that
must process one million records in sequence will accumulate 5,000 s – roughly 1 h
and 23 min – of unnecessary processing time.
One of the main challenges to tackle is the latency perceived by the end user.
In many cases, when there is a migration from a host-based environment to a web-
based application (a frequent occurrence in data-centered organizations) we have
to face the fact that the users take for granted the response times of terminal-
based applications, which are typically in the range of fractions of seconds. By
leveraging the use of the cache mechanisms built into HTTP, an application can
offer competitive response times and compare favorably against the terminal-based
applications in terms of features – not only in terms of speed. In contrast, services
must be carefully analyzed to determine what is cacheable and what is not. On
the other hand, implementing caching as a cross-cutting concern involves the use of
techniques that can be considered advanced, such as Aspect Oriented Programming.
In short, caching is a first class citizen in the reference architecture.
Uniform Interface
Fig. 15.4 This log traces show how the cache constraint can dramatically reduce response times
when GETting the same unchanged resource /office multiple times (200 OK HTTP response
code with 110 ms response time for the first request but 304 Not Modified response code
with 18 ms response time on subsequent requests – no JSP processing)
Fig. 15.5 An XTHML representation processing time for the /office/100121916 resource
7
Use of Accept header is a work in progress.
15 Practical REST in Data-centric Business Applications... 349
application from the Primary Key and Foreign Key relationships in the database.
Thus, the application is navigable in any of its representations, improving client–
server decoupling and enabling easy workflow management by a programmatic
client (Listing 15.1).
Fig. 15.6 A JSON representation processing time for the /office/100121916 resource
Listing 15.1 This is the ATOM representation of an employee which is related with an office and
with a set of customers. Those relationships are explicit in an ATOM representations thanks to its
hypermedia capabilities in lines 16 and 55. This representation can be customize to build a custom
Domain Application Protocol as stated in Parastatidis et al. (2010)
350 J. Fernandez and J. Rodriguez
1 < e n t r y>
2 < t i t l e > e x t e n s i o n< / t i t l e >
3 < a u t h o r><name />< / a u t h o r>
4 <summary t y p e ="text">x4871< / summary>
5 < / e n t r y>
6 < e n t r y>
7 < t i t l e >e m a i l</ t i t l e >
8 < a u t h o r><name />< / a u t h o r>
9 <summary t y p e ="text">
10 w p a t t e r s o n @ c l a s s i c m o d e l c a r s . com
11 < / summary>
12 < / e n t r y>
13 < e n t r y>
14 < t i t l e > r e p o r t S t o< / t i t l e >
15 < a u t h o r><name />< / a u t h o r>
16 <summary t y p e ="text">1056< / summary>
17 < / e n t r y>
18 < e n t r y>
19 < t i t l e > j o b T i t l e< / t i t l e >
20 < a u t h o r><name />< / a u t h o r>
21 <summary t y p e ="text">S a l e s Manager (APAC)< / summary>
22 < / e n t r y>
23 < e n t r y>
24 < t i t l e >c u s t o m e r s < / t i t l e >
25 < l i n k r e l ="alternate"
26 h r e f ="http://localhost:8080/show-web/customer.atom?
27 employee.employeeNumber=1088" />
28 < a u t h o r><name />< / a u t h o r>
29 <summary t y p e ="text">6< / summary>
30 < / e n t r y>
31 < / f e e d>
An application under the reference architecture will use HTTP response codes
strictly, such as 200 OK, 201 Created, 304 Not Modified, 400 Bad Request,
404 Not Found, 409 Conflict, 500 Internal Server Error or 501 Not Implemented
(Fielding et al. 1999). This is a vital feature to achieve HTTP based integration
with legacy systems and third-party software. Moreover, it reinforces the concept of
a uniform interface and provides a consistent behavior among presentation layers
based in different technologies.
The uniform interface, Hypermedia as the Engine of Application State (HA-
TEOAS) and the capability to serve multiple representations allow a high level of
decoupling between client and server, so it is possible to pursue gradual migrations
of the presentation layer (from a Web browser to a Rich Internet Application, for
instance) without altering the behavior of the server. In the worst case scenario,
it would be necessary to add a new representation, but that does not affect
existing clients. Most legacy systems can have seamless integration with RESTful
applications as long as they have the capability to perform HTTP requests, which
nowadays can be done in practically any platform from mainframes to embedded
systems.
15 Practical REST in Data-centric Business Applications... 351
Layered System
The layered quality of REST has allowed the incorporation of intermediary network
elements between clients and servers, improving the growth of the infrastructure
in network environments above the LAN mark. Moreover, the proxy acts as a
central request and response nexus, improving monitoring and growth-prevision
tasks. At an experimental level, Squid has been used as a RESTful proxy server
for RPC-based legacy systems, acting as a so-called “Enterprise Service Bus”
with all the benefits of a consistent interface but with reduced complexity, a
manageable codebase, simplified configuration and easy administration. Squid as
an intermediary is one of the more powerful actors in this kind of deployment; not
only for caching/acceleration, but also load balancing, routing, and other services
which comes at hand for one of our requisites: it is expected that this same software
platform would serve other countries
RESTful-based Integration
Initially, integration with the legacy systems was achieved through the product
supplied by the mainframe systems vendor, which at first was based in COM
and later acquired support for SOAP. This enabled a consistent, vendor-supported
coexistence between JEE applications and legacy mainframe code written in
COBOL. But in the other direction, the path was not that crystal clear. In the first
instance, even though there is a vendor-supported JVM for the legacy platform, its
memory and execution profile made its cost prohibitive for many tasks. And the
invocation path to access SOAP-based web services from COBOL legacy code is
convoluted at best.
Keeping this in mind, the first benefits of a REST-enabled architecture were
evident when the necessity arose to invoke business logic residing in the JEE
platform from COBOL legacy programs. Instead of relying on a complex solution
352 J. Fernandez and J. Rodriguez
Fig. 15.7 This figure depicts how the different elements of the architecture interact regarding the
CTI integration. The middleware take commands from a JMS queue and report CTI events back to
a JMS topic in an Apache ActiveMQ server. Communication with the queues is exposed through
a RESTful HTTP connector, allowing a web-based application to interact with the PBX for most
CTI operations
based in Java or in a SOAP stack accessible from C and painfully integrated with
COBOL, we wrote a tiny library for RESTful invocations using libCURL – a readily
available HTTP access library – implemented a thin wrapper for invocation from
COBOL programs in order to handle GET and POST requests through a consistent
interface and take care of the finer points of HTTP request handling. In a matter of
days, the mainframe was consuming RESTful web services in the Java platform.
A different challenge arose to interact with the CTI platform, which exposes
a proprietary interface with libraries available for Win32 and Linux, but clearly
intended to follow an strict client–server approach, with a middleware layer acting
as server and clients running in user PCs.
In this scenario, installing access libraries and heavy clients in user PCs negates
many of the side benefits of a web-based application deployment, mainly that there
is nothing to install besides the browser itself. And in a heavily decentralized
architecture like that suggested by the vendor, other concerns like performance
monitoring, access control, and security become progressively more expensive in
terms of implementation, supervision and maintenance.
In this case, we leveraged the REST architectural style by implementing a server
with a thin layer of logic over the vendor-supplied CTI library in order to let the
middleware take commands from a JMS queue and report CTI events back to a
JMS topic in an Apache ActiveMQ server (see Fig. 15.7). Then we exposed those
15 Practical REST in Data-centric Business Applications... 353
The code generation tool we have been using in this project is an in-house product
that has been christened Alquimia.8 In its most general form, it is a toolkit that
leverages best-of-breed frameworks to generate RESTful Web applications for the
Java platform. Alquimia was developed to support organizations that depend heavily
on data, like financial entities or insurance companies. These organizations have
in common two key characteristics: their business proposition relies deeply on
data management and they have an ongoing need to integrate external systems.
These characteristics translate into stable, long-lived data models and into multiple
interfaces and integration points – be it to coordinate existing business processes
with legacy systems or to synchronize information with ERP software, just to
mention a couple of examples.
As a toolkit, we can think of Alquimia as a collection of components that for the
sake of simplicity can be separated in two phases: code-generation on one hand, and
run-time support libraries on the other. The code-generation logic resides entirely in
a Maven 2 plug-in, and as such it can be integrated seamlessly in an existing build
toolchain. The run-time support libraries take the form of several interceptors for
Struts 2 and Spring, the latter acting as AOP logic. A key component is a series of
improvements on the Struts 2 REST plug-in that have been contributed back into
the upstream codebase.
The application generation process is as follows. Given a database model it only
takes a few moments to configure the JDBC connection parameters and execute
the proper Maven task in order to generate a RESTful Web application. This
application will expose the database tables as domain entities, and effectively as
REST resources.
Necessary training for application development using Alquimia is simplified
considerably when compared against training for traditional Java/JEE-based devel-
opment. The most common use cases observed in data centered applications are
already implemented by Alquimia. Moreover, its RESTful interface offers an easy
8
Alquimia will be opensourced in the near future. You can learn more at http://esilog.com/alquimia.
354 J. Fernandez and J. Rodriguez
pattern for the developers to understand and follow. The amount of configuration
is minimized as well, leveraging the convention-over-configuration approach. The
target application is ready to add the necessary business logic and views.
Our experience with the generative approach offered by Alquimia has delivered
existence proofs that such a technique improves productivity as well as maintains
coherence among generated applications. We encourage others to follow this path
when a domain specific architecture has been identified.
References
Fielding, R.T.: Architectural Styles and the Design of Network-based Software Architectures. Phd
Thesis, University of California, Irvine (2000)
Waldo, J., Wyant, G., Wollrath, A., Kendall, S.: A Note on Distributed Computing. Sun Microsys-
tems Laboratories, Inc. (1994)
Taylor, R.N., Medvidovic, N., Dashofy, E.M.: Software Architecture. Foundations, Theory, and
Practice. Wiley, NY, USA (2010)
Gamma, E., Johnson, R., Helm, R., Vlissides, J.M., Booch, G.: Design Patterns. Elements of
Reusable Object-Oriented Software. Addison-Wesley, Reading, MA (Wokingham, UK) (1994)
Parastatidis, S., Webber, J., Silveira, G., Robinson, I.S.: The Role of Hypermedia in Distributed
System Development. WS-REST 2010 (2010)
Fielding, R.T., Gettys, J., Mogul, J., Frystyk, H., Masiner, L., Leach, P., Berners-Lee, T.: RFC 2616.
Hypertext Transfer Protocol – HTTP/1.1 (1999) http://www.ietf.org/rfc/rfc2616.txt. Accessed
October 2010
Tomayko, R.: Things Caches Do http://tomayko.com/writings/things-caches-do. Accessed
October 2010
Part V
REST and Pervasive Computing
Chapter 16
RESTifying Real-World Systems:
A Practical Case Study in RFID
D. Guinard ()
Institute for Pervasive Computing, ETH Zurich, Switzerland
e-mail: [email protected]
Introduction
1
http://epcglobalinc.org/standards/architecture.
362 D. Guinard et al.
Fig. 16.1 Simplified view of the EPC Network and some of its main standards
goes through a filtering process and is eventually stored in an EPCIS together with
contextual data. In particular, these data deliver information about:
• The “what”: what tagged products (EPCs) were read.
• The “when”: at what time the products were read.
• The “where”: where the products were read, in terms of Business Location (e.g.,
“Floor B”).
• The “who”: what readers (Read Point) recorded this trace.
• The “which”: what was the business context (Business Step) recording the trace
(e.g., “Shipping”).
The goal of the EPCIS is to store these data to allow creating a global network
where participants can gain a shared view of these EPC traces. As such, the EPCIS
deals with historical data, allowing, for example, participants in a supply chain to
share the business data produced by their EPC-tagged objects.
16 RESTifying Real-World Systems: A Practical Case Study in RFID 363
2
http://autoidlabs.mit.edu/CS/content/OpenSource.aspx.
364 D. Guinard et al.
As mentioned before, in the EPCIS standard, most features are accessible through a
WS-* interface. To specify the architecture of the RESTful EPCIS we systematically
took these WS-* features and applied the properties of a Resource Oriented
Architecture (ROA) we summarized in the previous section.
All the services of a Resource Oriented Architecture are modeled with resources
which are components of an application worth being uniquely addressed and linked
to. Each resource gets a unique and resolvable address in the form of a URL.
Thus, the first step a ROA design is to identify the resources an EPCIS should
be composed of and to make them addressable. Looking at the EPCIS standard, we
can extract a dozen resources. We focus here on the four main types:
1. Locations (called “Business locations” in the EPCIS standard): those are loca-
tions where events can occur, e.g.,:“C Floor, Building B72”.
2. Readers (called “ReadPoints” in the standard): which are RFID readers registered
in the EPCIS. Just as Business Locations, readers are usually represented as
URIs: e.g., urn:br:maxhavelaar:natal:shipyear:incoming but
can also be represented using free-form strings, e.g.,: “Reader Store Checkout”
3. Events: which are observations of RFID tags, at a Business Location by a specific
reader at a particular time.
4. EPCs: which are Electronic Product Codes identifying products (e.g., urn:epc:
id:sgtin:618018.820712.2001), types of products (e.g., urn:epc:id
:sgtin:618018.820712.*) or companies (e.g., urn:epc:id:sgtin:
618018.*).
We first define a hierarchical organization of resources based on the following
URI template:
location/businessLocation/reader/readPoint/time/
eventTime/event
More concretely, this means that the users begin by accessing the Location
resources. Accessing the URL http://.../location/ with the GET method
retrieves a list of all Locations currently registered in the EPCIS. From there, clients
can navigate to a particular Location where they will find a list of all Readers at this
366 D. Guinard et al.
place. From the Readers clients get access to Time resources which root is listing all
the Times at which Events occurred. By selecting a Time, the client finally accesses
a list of Events.
Each event contains information such as its type, event time, Business Location,
EPCs, etc. If a client is only interested about one specific field of an Event, he
can get this information by adding the desired information name as sub-path of the
Event URI. For example, EVENT URI/epcs lists only all the EPCs that were part
of that Event. The resulting tree structure is shown in Fig. 16.2, and a sample Event
in Fig. 16.3.
Furthermore, in a ROA all resources should be discoverable by browsing to
facilitate the integration with the Web. Just as you can browse for Web pages,
we should be able to find RFID tagged objects and their traces by browsing.
Each representation of resources should contain links to relevant resources such as
parents, descendants or simply related resources. This property of ROAs is known
as “connectedness”.
To ensure the connectedness of the RESTful EPCIS, each resource in the tree
links to the resources below or to related resources. The links allow users to
browse completely through the RESTful EPCIS where links act as the motor. Every
available action is deduced by the set of links included. This way, people can directly
explore the EPCIS from any Web browser, simply by clicking on hyperlinks and
without requiring any prior knowledge of the EPCIS standard.
To ensure that the browsable EPCIS interface did not become too complicated,
we limited the number of available resources and parameters. For more complex
queries we provide a second, hierarchical, interface for which we map the EPCIS
16 RESTifying Real-World Systems: A Practical Case Study in RFID 367
Fig. 16.3 HTML representation of an EPC event as rendered by a Web browser, every entry is
also a link to the sub-resources
WS-* query interface to uniquely identifiable URIs. Each query parameter can
be encoded and combined as a URI query parameter according to the following
template
/eventquery/result?param1=value1&...¶mN=valueN
Query parameters restrict the deduced result set of matching RFID events. The
RESTful EPCIS supports the building of such URIs with the help of an HTML
form. If for example a product manager from Max Havelaar is interested in the
events that were produced in Palmas, the following URL lists all events that
occurred at this business location:
http://.../eventquery/result?location=urn:br:
maxhavelaar:palmas:productionsite
To further limit possibly very long search results, the query URI can be more spe-
cific. The manager might be interested only about what happened on that production
site on the 4th of November 2009, which corresponds to the following URL:
http:/../eventquery/result?location=urn:br:
maxhavelaar:palmas:productionsite&time=2009-11-04T00:
00:00.000Z,2009-11-04T 23:59:59.000Z
The HTML representation of this resource is illustrated in Fig. 16.3.
To keep the full connectedness of the RESTful EPCIS, both the browsable and
the query interface are interlinked. For example, the EPC urn:epc:id:sgtin:
0057000.123430.2025 included in the event of Fig. 16.3, is also a link to the
query which asks the EPCIS for all events that contain this EPC.
We leverage the addressability property to allow a greater interaction with EPCIS
data on the Web. As an example, since queries are now encapsulated in URLs,
we can simply bookmark them, exchange them in emails and consume them from
368 D. Guinard et al.
Finally, in a ROA, the resources and their services should be accessible using a
standard interface defining the mechanisms of interaction. The Web implementation
of REST uses HTTP for this purpose.
Multiple Representation Formats A resource is representation agnostic and
hence should offer several representations (e.g., XML, HTML). HTTP provides
a way for clients to retrieve the most adapted one. The RESTful EPCIS supports
multiple output formats to represent a resource. Each resource first offers an HTML
representation as shown in Fig. 16.3 which is used by default for Web browser
clients.
In addition to the HTML representation, each resource also has an XML and
a JSON (JavaScript Object Notation) representation, which all contain the same
information. The XML representation complies with the EPCIS standard and is
intended to be used mainly for business integration. The JSON representation can
be directly translated to JavaScript objects and is thus intended for mashups, mobile
applications or embedded computers.
The choice of the representation to use in the response can be requested by clients
using the HTTP “content negotiation” mechanism.3 Since content negotiation is
built into the uniform interface, clients and servers have standardized ways to
exchange information about available resource representations, and the negotiation
allows clients and servers to choose the representation that fits best a given scenario.
A typical content negotiation procedure looks s follows. The client begins with
a GET request on http://.../location. It also sets the Accept header of
the HTTP request to a weighted list of media types it can understand, for example
to: application/json, application/xml;q=0.5. The RESTful EPCIS
then tries to serve the best possible format it knows about and describes it in the
Content-Type of the HTTP response. In this case, it will serve the results in the
JSON format as the client prefers it over XML (q D 0:5).
Error Codes The EPCIS standard defines a number of exceptions that can occur
while interacting with an EPCIS. HTTP offers a standard and universal way of
communicating errors to clients by means of “status codes”. Thus, to enable clients,
especially machines to make use of the exceptions defined by the EPCIS specifica-
tion, the RESTful EPCIS maps the exceptions to HTTP status codes. An exhaustive
list of error codes and their meanings for Resource Oriented Architectures can be
found in Richardson and Ruby (2007).
3
http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html.
16 RESTifying Real-World Systems: A Practical Case Study in RFID 369
In many cases, it would be useful to group tagged objects into collections according
to certain properties or scenarios (example collections would be “all the milk bottles
shipped today to rhode island” or “potatoes shipped to client no 3”), and be able to
monitor the state of collection through a syndication mechanism. The Atom Syndi-
cation Format is an XML language specifying the syntax of Web feeds. With Atom,
the Web has a standardized and RESTful model for interacting with collections,
and the Atom Publishing Protocol (AtomPub) extends Atom’s read-only interactions
with methods for write access to collections. Because Atom is RESTful, interactions
with Atom feeds can be based on simple GET operations which can then be cached.
Fig. 16.4 Architecture of the RESTful EPCIS based on the Jersey RESTful framework and
deployed on top of the Fosstrak EPCIS
370 D. Guinard et al.
After the design of RESTful Services, comes their implementation. The recent
regain of interest for RESTful services has led to a number of frameworks helping
developers in this step. In this section we will look at some of these frameworks,
focusing on their features and benefits when applying the constraints of RESTful
architectures. However, let us begin by looking at integration patterns at a higher
level: given an existing information system, what integration options do we have?
When creating an information system from scratch, the constraints for RESTful
architectures are of great help in defining the data model. There are also no major
conflicts between the REST paradigm and the Object Oriented paradigm. Indeed,
Object Oriented programming defines an internal, application centric, contract.
REST, on the other hand, defines a contract with the world outside the application
(this is why developers often speak about RESTful APIs) towards a distributed and
remote usage of its functionality. Thus, both can cohabit nicely to create a distributed
Web application, as long as they are designed together. However, adding a RESTful
architecture to an existing WS-* centric information system can be challenging as
both paradigms share the same basic goal: creating remotely re-usable services.
16 RESTifying Real-World Systems: A Practical Case Study in RFID 371
Woven REST
As shown on Fig. 16.5, there are basically two ways of achieving an integration;
First (a) on Fig. 16.5), the RESTful architecture can be directly woven into the
existing WS-* system. This may seem like a trivial solution at first; however,
the implementation of this solution is not entirely straightforward. While sharing
a common goal, WS-* and REST are rooted on very different paradigms. Thus,
weaving clean REST architecture into the core of the WS-* system almost always
requires an alternate data model. Using two different data models for the same
services ends up in rather complicated architectures.
REST Adapter
350
REST
WS
300
RTT+Processing [ms]
250
200
150
100
50
0
Many Results Few Results Complex Query
Fig. 16.6 Average RTT and processing time when using the WS-* interface and the REST
interface for three types of requests each run 100 times
with the constraints of RESTful architectures. As shown on the left of the picture,
the typical clients of the RESTful EPCIS are different from the business applications
traditionally connected to the EPCIS. The browser is the most prevalent of these
clients. It can either directly access the data by means of URL calls or indirectly
using scripted Web pages.
Performance Evaluation
As mentioned before, the translation between REST and WS-* (and vice-versa)
results in an overhead that we briefly evaluate here.
The experimental setup is composed of a Linux Ubuntu Intel dual-core PC 2.4
GHz with 2 GB of ram. We deploy Fosstrak and the RESTful EPCIS on the same
instance of Apache Tomcat with a heap size of 512 MB. We evaluate three types of
queries all returning the standard EPCIS XML representation.
The first query (Q1, “Many Results” in Fig. 16.6) requests all events recorded by
the EPC, i.e., a small request returning a document of 30 KB with 22 events each
composed of about 10 EPCs. In the second test (Q2, “Few Results”), is a query
returning a document of 2.2 KB with only two results. The last test (Q3, “Complex
Query”) is a query containing a lot of parameters and returning ten events. We test
each of these queries asking for the standard XML representation. All queries are
repeated 100 times from a client located on a machine one hop away from the server
with a Gigabit ethernet connectivity. The client application is programmed in Java
and uses a standard JAX-WS client for the WS-* calls and the standard Apache
HTTP Client and DOM (Document Object Model) library for the REST calls.
16 RESTifying Real-World Systems: A Practical Case Study in RFID 373
As shown on Fig. 16.6, for Q1 the RESTful EPCIS has an average overhead of 30
ms due to the computational power required to translate the requests from REST to
WS-* and vice-versa. For Q2 and Q3 the REST requests are executed slightly faster
(about 20 ms) than the WS-*. This is explained by three factors. First, since there are
fewer results, the local WS-* request from the RESTful EPCIS is executed faster.
Then, REST packets are slightly smaller as there is no SOAP envelope (Yazar and
Dunkels 2009). Finally, unmarshalling WS-* packets (using JAXB) on the client-
side takes significantly longer than for REST packets with DOM. For Q3, similar
results are observed. Overall, we can observe that the RESTful EPCIS creates a
limited overhead of about 10% which is compensated in most cases by the relatively
longer processing times of WS-* replies. This becomes a particularly important
point when considering devices with limited capabilities such as mobile phones or
sensor nodes as well as for client-side (e.g., JavaScript) web applications.
It is worth mentioning that the WS-* protocol can be optimized in several ways
to better perform, for example by compressing the SOAP packets and optimizing
JAXB. However as the content of HTTP packets can also be compressed this is
unlikely to drastically change the results. Furthermore, because they encapsulate
requests in HTTP POST, WS-* services cannot be cached on the Web using standard
mechanisms. For the RESTful EPCIS however, all the queries are formulated as
HTTP GET requests and fully contained in the request URL. This allows to directly
leverage from standard Web caching mechanisms (Fielding and Taylor 2002) which
would importantly reduce the response times (Yazar and Dunkels 2009).
Creating clients for RESTful Web Services is a rather straightforward task as it only
requires for the used language to support HTTP, which most modern programming
and scripting languages do. The implementation of a RESTful Web Services, on
the other hand, is a task that should not be underestimated. Indeed, even if the
set of REST constraints is seemingly small their implementation requires a careful
software design.
Most modern Web languages such as Ruby (especially in its Ruby on Rails form)
or Python offer out-of-the-box support for RESTful Web Services. Similarly, the
recent growing interest for lightweight service architectures based on REST has
given birth to a number of frameworks that simplify the development of RESTful
applications for enterprise-scale languages such as C# or Java.
The Java community is a particularly interesting one since it is known as one of the
community with most WS-* tools and frameworks but also as one of the most eager
to develop tools around REST (perhaps due to some frustrations with the WS-* type
of services...).
374 D. Guinard et al.
In particular, the Java galaxy has its own higher-level industrial standard for
building RESTful Web Services: the JAX-RS API4 (also known as JSR 311). JAX-
RS is especially interesting since it was developed by a consortium of people who
are both Web-specialists and service developers. The result is a very lean API [well
described in Burke (2009)] that requires a good understanding of REST but offers
straightforward solutions to implement in an elegant and efficient way most of the
REST constraints.
In short, JAX-RS is based on three main pillars. It first uses annotations of Java
classes to turn them into resources (e.g., @Path(‘‘/location’’)), ensuring
the Resource Identification constraint. Annotations further help to define the
resources’ Uniform Interface as it lets the developer specify allowed verbs (@GET,
@POST) and served representations (e.g., @Produces(MediaType.APPLICAT
ION JSON)). Beyond annotations, several framework classes make the developer
life easier. Connectedness is boosted by providing contextual URI Builders,
letting the developer easily link resources together across representation. Finally, the
use of the JAXB framework allows for Java Objects to be automatically serialized
to an (extensible) number of representations such as XML, HTML, JSON and Atom
thus making it easier to fulfill the constraint for Self-Describing Messages.
Besides Jersey,5 the reference implementation of JAX-RS, several frameworks
such as RESTeasy, Apache Wink, Apache CFX and RESTlet are JAX-RS compliant
which makes it rather easy to move code from one framework to the other.
As shown in Fig. 16.4, the core of the RESTful EPCIS is based on the JAX-RS
compliant, Jersey6 framework. Thus, it uses JAX-RS annotations and framework
classes. The example below serves the representation of a location resource.
1 @Path(\location\{businessLocationID})
@GET
3 @Produces({MediaType.APPLICATION_XML, MediaType.
APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML,
MediaType.TEXT_HTML})
public Resource getSelectedBusinessLocation(@Context
UriInfo context, @PathParam("businessLocationID")
String businessLocation) {
5 QueryBusinessLogic logic = new QueryBusinessLogic();
return logic.getSelectedBusinessLocation(context,
businessLocation);
7 }
4
http://jcp.org/en/jsr/detail?id=311.
5
http://https://jersey.dev.java.net.
6
https://jersey.dev.java.net.
16 RESTifying Real-World Systems: A Practical Case Study in RFID 375
Line 1 of this listing sets the URI of the resource, where businessLocationID
is the location identifier which will be dynamically passed to the method
getSelectedBusinessLocation at runtime. @GET specifies the method
allowed on this resource, @Produces contains the representations that clients
will be able to obtain through content negotiation. Note that these contents will be
automatically generated at runtime from the Resource Java Object by the JAXB
framework.
As we can see, the RESTful EPCIS uses Jersey for managing the resources’
representations and dispatching HTTP requests to the right resource depending on
the request URL. When correctly dispatched to the RESTful EPCIS Core, every
request on the querying or browsing interface is then translated to a WS-* request on
the EPCIS. This makes the RESTful EPCIS entirely decoupled from any particular
implementation of an EPCIS.
While JAX-RS offers serving Atom representation of resources on-the-fly,
implementations of JAX-RS do not have to offer a fully-featured Atom-Pub server
with persistence. Thus, for the subscription interface we used Apache Abdera, which
is an open-source implementation of an Atom-Pub server integrating well with most
JAX-RS frameworks. Every time a client subscribes to a query, the RESTful EPCIS
checks whether this feed already exists by checking the query parameters, in any
order. If it is not the case it creates a query on the WS-* EPCIS and specifies the
address of the newly created feed. As a consequence every update of the query is
directly POSTed to the feed resource which creates a new entry using Abdera and
stores it in an embedded SQLite7 database.
Jersey, Abdera and SQLite are packaged with the RESTful EPCIS core in a Web
Application Archive (WAR) that can be deployed in any Java compliant Web or
Application Server. We tested it successfully on Glassfish8 and Apache Tomcat9
and on the Grizzly embedded Web Server.10
As RFID objects become part of the Web, applications using them can be developed
using popular Web languages (e.g. HTML, JavaScript, PHP, Python) and toolkits,
(e.g., DOJO, jQuery, Closure). This can significantly ease the developments on the
RFID middleware vendor’s side, since applications can be built on languages for
which a plethora of libraries and toolkits are available. Furthermore, the use of
popular languages makes it easier to find adequate developers. Likewise, this also
unveils the possibility for external developers to create innovative Web applications
7
http://www.sqlite.org.
8
http://glassfish.org.
9
http://tomcat.apache.org.
10
http://grizzly.dev.java.net.
376 D. Guinard et al.
making use of RFID data. Open APIs and communities of developers have long
become vital for service companies on the Web such as Facebook, Twitter, or
Google. This direction is also being taken upon by many electronic devices (sensor
nodes, appliances, etc.). New hardware on the market such as the Chumby alarm
clock11 or the Squeezbox HiFi system12 already have significant communities of
voluntary Web developers creating dozens of small applications for each platform.
Adding a RESTful module to the EPCIS brings it one step closer to these
promising opportunities, where the consumers become active actors, not just passive
consumers. Just as users create Web 2.0 mashups (Yu et al. 2008) by integrating
several Web sites to create new applications, companies buying RFID systems can
re-use RFID events to create ad-hoc, innovative applications in an easier manner.
The EPCIS RESTful API allows a wider range of developers, tech-savvy users
(technologically skilled people) or researchers to develop on top of the EPCIS and
contributes to helping the EPC Network developer community grow.
To better illustrate the new type of applications the RESTful EPCIS unveils, we
created the EPC Dashboard Mashup, a Web mashup, that helps product, supply
chain and store managers to have a live overview of their business at a glance. It can
further help consumers to better understand where the goods are coming from and
what other people think about them. The EPC Dashboard is based on the concept of
widgets in which the events data are visualized in a relational, spacial or temporal
manner.
The EPC Dashboard consumes data from the RESTful EPCIS. Usually these
data are hard to interpret and integrate. The dashboard makes it simple to browse
and visualize the EPC data. Furthermore, it integrates the data with multiple sources
on the Web such as Google Maps, Wikipedia, Twitter, etc.
Mashup Architecture
11
http://www.chumby.com.
12
http://www.logitechsqueezebox.com.
16 RESTifying Real-World Systems: A Practical Case Study in RFID 377
Fig. 16.7 The Maps widget is following the route of the banana tagged with the EPC
urn:epc:id:sgtin:0057000.123430.2025
Fig. 16.8 The Product Buzz Widget extracts live opinions and information about particular
products (here Lindt Chocolate) from Twitter
378 D. Guinard et al.
All widgets are connected to each other which means that actions on a given one
can propagate the selection to the other widgets and changes their view accordingly.
As such, widgets listen to selections and can make selections. This interaction is
implemented using the observer pattern (Gamma et al. 1994) where consumers (i.e.,
the widgets) register to asynchronous updates of the currently selected Locations,
Readers, Time or EPCs. This architecture allows the creation and integration of
other Web widgets with very little effort. The EPC Dashboard itself is a JavaScript
application built using the Google Web Toolkit,13 a framework to develop rich Web
clients. This has been possible because having a RESTful Interface upon the EPCIS
eases the development of mashups.
Summary
In this chapter we argue that RESTful architecture can greatly contribute to the
success and public innovation around an Information System. We further argue for
thinking of these systems as Web APIs rather than as applications. As an illustration
we describe how we applied the principles and constraints of RESTful architectures
to the world of RFID for creating the RESTful EPCIS open-source project which
is released as an open-source module of the Fosstrak project, under the name of
epcis-restadapter.14
RESTifying the EPCIS literally brings RFID traces to the Web, as every tagged
product, reader, location, etc. become fully addressable resources. Using the HTTP
protocol tagged objects can be directly searched for, indexed, bookmarked, ex-
changed and feeds can be created by end-users. Furthermore, this enables exploring
the EPCIS data simply by browsing them, which helps making sense of the data. We
argue that this adds more flexibility to the types of applications that can be built on
top of an EPCIS and opens the EPCIS API for fast-prototyping to the very large and
active community of Web and mobile developers. We further show that this added
flexibility does not necessarily have to hinder the overall performances, deploying
the RESTful EPCIS on the same machine as the WS-* EPCIS leads to satisfactory
results while preserving the EPCIS-vendor independence.
We finally illustrate the new application space the RESTful EPCIS unveils by
means of a JavaScript Mashup: the EPC Dashboard which is an easily extensible
business intelligence interface for product managers that re-uses a number of
Web APIs.
13
http://code.google.com/intl/en/webtoolkit.
14
http://www.webofthings.com/rfid.
16 RESTifying Real-World Systems: A Practical Case Study in RFID 379
References
Bill Burke. RESTful Java with Jax-RS. O’Reilly Media, 1st edition, November 2009.
Roy T. Fielding and Richard N. Taylor. Principled design of the modern Web architecture. ACM
Trans. Internet Technol., 2(2): 115–150, 2002.
Christian Floerkemeier, Matthias Lampe, and Christof Roduner. Facilitating RFID Development
with the Accada Prototyping Platform. In Proceedings of the Fifth IEEE International
Conference on Pervasive Computing and Communications Workshops, pages 495–500. IEEE
Computer Society, Silver Spring, MD, 2007.
Erich Gamma, Richard Helm, Ralph Johnson, and John M. Vlissides. Design Patterns: Elements
of Reusable Object-Oriented Software. Addison-Wesley Professional, Reading, MA (Woking-
ham, UK), November 1994.
Dominique Guinard, Vlad Trifa, and Erik Wilde. A Resource Oriented Architecture for the Web of
Things. In Proceedings of IoT 2010 (IEEE International Conference on the Internet of Things),
Tokyo, Japan, November 2010.
Dominique Guinard, Felix von Reischach, and Florian Michahelles. MobileIoT Toolkit: Con-
necting the EPC Network to MobilePhones. In Proceedings of Mobile Interaction with the
Real World at Mobile HCI (MIRW), The University of Oldenburg, Amsterdam, Netherlands,
September 2008.
Tim Kindberg, John Barton, Jeff Morgan, Gene Becker, Debbie Caswell, Philippe Debaty, Gita
Gopal, Marcos Frid, Venky Krishnan, Howard Morris, John Schettino, Bill Serra, and Mirjana
Spasojevic. People, places, things: web presence for the real world. Mob. Netw. Appl., 7(5):
365–376, 2002.
T. Luckenbach, P. Gober, S. Arbanowski, A. Kotsopoulos, and K. Kim. TinyREST – A protocol for
integrating sensor networks into the internet. In Proceedings of the Workshop on Real-World
Wireless Sensor Network (SICS), Stockholm, Sweden, 2005.
Cesare Pautasso and Erik Wilde. Why is the Web Loosely Coupled? A Multi-faceted Metric
for Service Design. In Proceedings of the 18th International World Wide Web Conference
(WWW’09), Madrid, Spain, April 2009.
Cesare Pautasso, Olaf Zimmermann, and Frank Leymann. Restful Web Services vs. Big Web
Services: Making the Right Architectural Decision. In Proceedings of the 17th International
Conference on World Wide Web (WWW), pages 805–814, ACM, New York, NY, USA, 2008.
Leonard Richardson and Sam Ruby. RESTful Web Services. O’Reilly Media, Inc., May 2007.
Dogan Yazar and Adam Dunkels. Efficient Application Integration in IP-based Sensor Networks.
In Proceedings ACM of the First ACM Workshop on Embedded Sensing Systems for Energy-
Efficiency in Buildings (BuildSys), Berkeley, CA, USA, November 2009.
Jin Yu, Boualem Benatallah, Fabio Casati, and Florian Daniel. Understanding Mashup Develop-
ment. IEEE Internet Comput., 12(5): 44–52, 2008.
Chapter 17
Leveraging the Web for a Distributed
Location-aware Infrastructure for the Real
World
Abstract Since GPS receivers have become a commodity anyone could access and
use location information simply and freely. Such an easy access to one’s location is
instrumental to the development of location-aware applications. However, existing
applications are static in that they do not model relations between places and mobile
things. Moreover, these applications do not allow to easily map the physical location
of mobile devices to virtual resources on the Internet. We attempt to bridge this gap
by extending the base concepts that make up the Internet with the physical location
of devices, in order to facilitate the development of Web-based location-aware
applications for embedded mobile devices. In this chapter, we propose a simple
infrastructure for the “Web of Things” that extends the existing Web to enable
location-aware applications. The proposed solution enables a naturally hierarchic
way to search for location-aware devices and the services they provide.
Introduction
In the last decade, tiny computers with various onboard sensors have been
increasingly installed in our buildings and cities. Connecting all these sensors
to a unique infrastructure has the potential to significantly affect our daily lives
by facilitating access to massive amounts of real-time data and reacting rapidly
to various conditions. For example, a manufacturing company could monitor and
detect events or anomalies in the production line rapidly, thus could react and
prevent stops of production or even accidents by having an instant view of what is
happening across the various locations of the company at any given time.
V. Trifa ()
Institute for Pervasive Computing – ETH Zurich, Universitätstrasse 6, 8092 Zurich, Switzerland
e-mail: [email protected]
As the usage of such networked sensing devices will spread, efficient – yet
simple – mechanisms and tools for automated data acquisition and manual inter-
action or control will be increasingly required. As more and more devices will need
to interact and work with each other in an ad hoc manner, an interoperable and open
infrastructure for seamless integration and usage of devices will become a necessity.
Recent efforts in the Web of Things (WoT) (Guinard et al. 2010) domain have
shown that REST (Fielding and Taylor 2002) is an appropriate architectural style
for building pervasive computing applications. Various prototypes have illustrated
the advantages associated with the use of Web technologies for ad hoc interaction
with devices. However, the lack of a scalable and flexible infrastructure to support
and automate the search and discovery of devices based on their characteristics
represents a major obstacle when building large-scale applications on top of
thousands of heterogeneous and mobile sensing devices.
At any given time, any person or object has a unique location in the physical
world (home, office, car, etc.). In contrast, the physical location of data is irrelevant
on the Web, since an efficient mechanism (universal resource identifiers, URI) is in
place to access data regardless of where it is actually stored. For the Web to truly
embrace the physical world, one needs to extend the classic Web model to make
it easy to bind real-time contextual information to things and use this information
to search things. The centralized index approach commonly used by search engines
seems appropriate for storing massive amounts of historical data. However, when
it comes to monitoring millions (or billions) of resources that will form the Web
of Things, a radically different approach is required. As more and more things will
have to be monitored in real-time, a centralized repository to store and query their
status would hardly scale. Present-day location-aware services such as Gowalla1
or Foursquare2 are nothing more than classical Web applications, therefore direct,
ad hoc interaction with physical places and their services is impossible without
being mediated through the remote server.
Although the cheap GPS receivers embedded in mobile phones have played
a central role in the popularization of such location-aware applications, they
are not useable when it comes to indoor localization. Because it does not rely
on an expensive or dedicated infrastructure, Wi-Fi fingerprinting is becoming a
particularly viable alternative that works at a city-scale and even indoors. With an
accuracy of a few meters, room-level localization is reasonably feasible which is
sufficient for most ubiquitous computing applications (Abowd et al. 2000). Even
though spatial localization techniques are constantly improving open and physically
distributed location-aware applications are still prevented by the lack of robust and
open standards for modeling and representing locations on the Web in a more
flexible format than geographical coordinates (Wilde and Kofahl 2008). Due to
the lack of tools and techniques to support natively the physical location of things
on the Web, discovering devices present in a certain place and interacting with
1
http://gowalla.com/.
2
http://foursquare.com/.
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 383
The success of the World Wide Web stems from its particular software architec-
ture called Representational State Transfer (REST), which emphasizes scalability,
generic interfaces, and a loose coupling between components (Fielding and Taylor
2002). On the Web, the primary abstraction of information and functionality are
resources that are identified by Uniform Resource Identifiers (URIs) and can
be interacted with using the HTTP protocol. Although HTTP was designed as
an application protocol with particular strengths (and weaknesses), many Web
applications today reduce its role to a mere transport protocol by using only a
fraction of its features. For example, Web applications that rely upon Web services
based on SOAP and WSDL use only a single operation of HTTP (POST) to call API
methods offered by a few URI-identified endpoints, thus hiding the actual resources
384 V. Trifa et al.
being manipulated. This prevents to take full advantage of the Web architecture’s
features and tools (e.g., caching, load balancing, etc.), as it requires to define specific
application layers for each application.
Web-enabling Things
The term Internet of Things (IoT) refers to networked devices with an emphasis
on interoperability at the data transport layer to maximize raw performance
through customized, tightly-coupled applications. More recently, the Web of Things
(WoT) (Guinard et al. 2010) vision proposed a shift towards simplified integration
and programming by reusing well-known Web standards to interact with embedded
devices. This way, common Web tools (e.g., browsers), interaction techniques,
and languages can be directly used to program the physical world. Following
the success of Web 2.0 mashups, we suggest that a similar lightweight approach
for interacting with embedded devices using HTTP to manipulate URI-identified
resources, significantly reduces the time required to develop applications for devices
and enables the creation of physical mashups (Guinard and Trifa 2009).
Another advantage of Web protocols over lower-level Internet protocols when
connecting smart real-world devices to the cyberspace is that one inherits many of
the mechanisms that made the Web scalable and successful for example caching,
load balancing, indexing, and searching as well as the stateless nature of the HTTP
protocol. One can also leverage search engines to register and index a physical
service (e.g., monitoring environmental sensors), by using semantic annotations to
describe the functionality and interaction possibilities of each device.
Embedded devices usually have limited resources and therefore require op-
timized protocols to exchange data. Additionally, as HTTP or IP might not be
available or appropriate for such devices, we propose to use gateways to enable
Web-based interactions with low-power devices. Such a gateway (cf. Fig. 17.1) is
nothing more than a Web application that enables access to heterogenous devices
through a simple and uniform RESTful API, thus hiding the complexity of the
various protocols used by the devices (such as Bluetooth or Zigbee). The gateway
application is lightweight enough to run on any programmable computer with a
TCP/IP connection that can run Java, as for example programmable wireless routers,
network-attached storage (NAS) devices, or networked media players.
Search engines have allowed to index and search the whole Web, we believe that
the next evolution will be the search for real-time data in the physical world. As
demonstrated by the success of the Web, a loosely-coupled physically distributed
application can scale massively. To replicate this characteristic, in this chapter we
explore how one can bind gateways and their associated devices together to form
a large infrastructure that integrates all kinds of devices over the Web. Such an
infrastructure could enable to search and use devices according to their current state,
location or overall context on a global scale and in real time.
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 385
Fig. 17.1 A gateway is a Web application to bridge embedded devices to the Web by hiding the
various low-power protocols used by devices behind a RESTful API
A central property of the Web is the use of hyperlinks to connect related resources
possibly using semantically annotated links (for example using friend of a friend,3
FOAF.) To create a distributed infrastructure for smart things, we propose to bind
gateways together in a similar manner. In previous work, we have explored how
gateways can be linked to realize a distributed location-aware infrastructure for
devices (Trifa et al. 2010). By assigning each gateway to a unique location and
linking gateways together according to their spatial disposition, one can model the
relations between places in the real world. In practice, this requires each gateway to
maintain a list of links (URI) towards the gateways of (physically) adjacent places,
and eventually to semantically annotate the nature of these links.
As illustrated in Fig. 17.2, such a Web-based hierarchical model of places enables
ad hoc and mobile interaction with the real world at different levels of granularity
(country, region, city, street, building, floor, room, object). Thanks to the layered
system style of the REST architecture, each node (represented by a gateway) in
the tree acts as an abstraction layer to interact with the devices and other gateways
contained in its subtree, thus refines its parent by offering a finer granularity for
clients that use the infrastructure. Such location-aware gateways are also called
location proxies, and both terms are used interchangeably throughout this chapter.
We also differentiate between two types of gateways: virtual and physical. Although
identical from a software point of view, the difference lies in the fact that physical
gateways (also called terminal gateways) must run on a computer (e.g., a wireless
3
http://www.foaf-project.org/.
386 V. Trifa et al.
Fig. 17.2 Example gateway hierarchy from our building. The top gateway covers the gateways for
each floor, and is composed only of virtual gateways. The southWing gateway runs on the router
that bridges the local sub-network of that area, thus can access all terminal gateways running on
computers physically located in each room. Terminal gateways have different physical interfaces
to access mobile devices nearby
router, a PC, etc.) physically located in the area it maps to, and also must possess
various physical interfaces to connect with devices in that location using short-range
radio protocols such as Wi-Fi, ZigBee or Bluetooth. Virtual gateways, on the other
hand, do not require to be installed physically located in the specific place that they
act as a location proxy for, as they don’t need to connect directly to physical devices.
To give an example, the virtual gateways of the tree shown in Fig. 17.2 can be fully
distributed across servers anywhere in the world transparently as long as the logical
structure of the tree is maintained.
The mapping process that assigns the logical place name (room 44, floor D, east
wing, etc.) to gateways must be done once manually by the developer at setup time.
Fortunately, since gateways are not mobile and the structure of their connections is
rather static, little effort is required to maintain the tree structure once designed.
Terminal gateways can discover mobile devices in their surroundings and make
them dynamically available as Web resources accessible over HTTP. This allows
to navigate the tree by following links to surrounding gateways simply by clicking
the links on a Web page or typing its URL in any Web browser.
On top of this network, one can easily build a system that supports range and
lookup queries for mobile devices. Unlike most other hybrid models for spatial
queries, our approach does not rely on a centralized database to store information
about the system. Thanks to their RESTful interfaces, gateways are loosely-coupled
components responsible for managing devices (and other gateways) located in the
area they are associated with. The higher up a node is situated in the hierarchy,
the less often things are likely to change, which naturally forms an efficient
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 387
load-balancing system, as users only need to access gateways located in the area
of interest without soliciting the rest of the system. As the loose coupling of the
location proxies also enhances the scalability and flexibility of the infrastructure,
this architecture is also particularly suited for ad hoc interaction with/from mobile
devices that move across locations.
Localization
Given that many different localization techniques exist for different applications, the
representation of the location information must be kept agnostic of the localization
technique used to maximize flexibility and interoperability. Although many formats
to represent outdoor locations have been developed recently, there is no standard
way to represent indoor location information, and certainly none based on Web
standards. As geographic coordinates (longitude/latitude) are not practical for
dealing with location concepts used in everyday life, as for example a room’s
number or a building wing’s name, a flexible model that supports user-generated
symbolic annotations of places is needed. Sharing semantics of places can be a
tedious problem in case a central authority has to maintain a repository of place
names, besides it would conflict with the Web’s decentralized nature.
To solve this problem, we propose to use the Web itself as a lookup service to find
and explore locations, as well as to obtain information about places and the devices
therein. Following the idea formulated in Jiang and Steenkiste (2002), we use URIs
to represent locations and their containment relations as a logical path according
to the URI definition. Consequently, RESTful URIs can be created dynamically by
navigating the hierarchical tree formed by the gateways. For each URI, both ma-
chines and people should be able to retrieve a description of the identified resource.
This is essential for a shared understanding about the location identified by the
URI, where machines can retrieve semantically annotated data (e.g., using RDFa or
Microformats) while people can retrieve a human readable representation (HTML).
Once the gateway hierarchy is in place, the problem of determining the current
location of a user on the tree still remains. In particular, when several gateways are
present on the same network, how does a client know which of these is the one corre-
sponding to its location? We call this the bootstrap problem, and a simple method to
infer the relevant location proxy’s URI based on one’s current location is necessary.
One possibility would be to always connect automatically to the gateway with the
highest signal strength, however, in practice this turns out to be very unstable as the
signal strength is subject to significant and unpredictable fluctuations.
The actual spatial localization process is not part of our project, therefore we
assume an indoor localization system for finding our position at the room level. For
example, we could use a system such as RedPin (Bolliger 2008) to automatically
return the URI of the location proxy associated with the current location. The
process of binding to a gateway itself should be as easy as possible, at any place
where wireless connectivity is available.
388 V. Trifa et al.
http://host{/location}[/keyword]
Here, the host denotes the network location of the local gateway (i.e., its IP
address or network name). To traverse the location structure, /location is used
to represent a path of arbitrary length (for example /building44/room3/).
Finally, by specifying a keyword, the user can search for devices and services
that match the expression. With this simple syntax, URIs become a flexible search
bar. For example, to instruct a gateway to return all its links (i.e., sub-resources) to
other devices or gateways, the wildcard character “*” can be appended to the URI
of any gateway. To find all devices tagged with the keyword phone located on the
same floor, one can simply type the following URL in any browser:
http://here/floor/phone/*
This URI can be resolved by the access point the user is associated with by
using the symbolic hostname “here/” – such requests can always be routed to
the “nearest” location gateway because the links between gateways are tagged
semantically. Subsequently, a HTML page with links to all the devices that match
the query and are under the nearest gateway named floor at that time will be
generated dynamically. In this setting, the same URI will yield different results
depending on the node in the network that it is routed to. This allows to create fixed
URIs that actually point to different resources depending on the geographic location
where it is issued, which is an interesting metaphor that many location-aware Web
applications can benefit from.
A central challenge when building the Web of Things (WoT) is the development of
a meaningful structure on top of individual resources attached to the WoT. Because
it matches the layered architecture of the Web (Fielding 2000), we opted for the
hierarchical location model described above where each node is responsible for
all devices in its proximity and every proxy on a lower hierarchical level. When
following this model to map physical locations to URIs, networks of gateways
automatically are organized into a rooted tree, where the root represents the highest
level of hierarchical location (for example the headquarters of an international
organization). The hierarchical approach has been proposed in early research (Trifa
et al. 2010) and shows some benefits with respect to load balancing and scalability
as users mostly access devices located in their surroundings. Our efforts in designing
and implementing such an architecture led towards the development of the InfraWoT
system. An important design choice for InfraWoT was that every communication
between proxies does happen locally (i.e., between neighboring nodes in the tree
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 389
structure). This helps to scale the infrastructure, as each gateway only requires
knowledge about its direct neighbors, thus can remain ignorant of the remaining
hierarchy.
Selecting information on the hierarchical location as the main structural
descriptor has immediate implications on several components of the infrastructure,
for instance on the service responsible for querying within the InfraWoT tree struc-
ture or on the module in charge of maintaining the correct infrastructure internally
(i.e., deciding which gateway to choose as parent and which to accept as children).
Modules Overview
4
http://www.osgi.org.
390 V. Trifa et al.
europe/
at/ ch/
tuvienna/ uzh/
Discovery Infrastructue
service service
koh/ kol/
Querying Registry
service service
Fig. 17.3 Modules running in each InfraWoT node that interact via OSGi declarative services
• Registry Service Module. This component manages data about attached resources
(both locally connected devices and neighbor gateways) and stores this informa-
tion into a local (typically embedded) database.
• Messaging Service Module. This module offers a transparent interface to set up a
messaging (i.e., publish/subscribe) system between client applications, gateways
and physical devices attached to the Web of Things.
• Querying Service Module. This module is responsible for handling incoming
queries. It retrieves local resources that correspond to the query and forwards
the query to suitable sub- or super-nodes.
• Web Interface Module. This module provides a Web interface that allows to
access the various functions offered by the gateway, either via a RESTful API
or via an actual Web-based user interface accessible from any browser. The
Web server is built upon Restlet5 and offers various device- and gateway-specific
functions.
5
http://www.restlet.org/.
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 391
2 1
3
3
4
4
Fig. 17.4 Sequence diagram of the RESTful discovery process of devices. (1) Device connects
to LAN/WiFi and gets an IP address from the router using DHCP. (2) The gateway monitors the
router’s DHCP table. (3) For each new device found, the gateway retrieves the root device page
(by default a HTTP server running on port 80) and parses it to find information about the device.
(4) The gateway retrieves the semantic description of the device
discovery protocol, but rather just have to provide semantic information about
themselves in their root document. In this section, we will describe the process of
attaching a new resource (i.e., a networked device featuring a RESTful interface) to
the InfraWoT system.
Device Discovery
The first step of the discovery process deals with finding new WoT devices that are
connected to a network. Here, we do only assume Ethernet/WiFi-enabled devices
as, for other protocols, a gateway is necessary.
Most existing discovery solutions rely on devices multicasting UDP messages
over the network. However, as such messages are not part of HTTP, they can often
be blocked by firewalls. We therefore propose a REST-based protocol to perform
network device discovery, which is shown in Fig. 17.4. We assume that in each
network, the router always knows the connected network devices (usually a table of
automatically assigned IP addresses), and as such can provide all required discovery
information. To access this information, our solution uses OpenWrt6 which is widely
used, open source Linux distribution available as firmware that can run on many
6
http://openwrt.org.
392 V. Trifa et al.
modern network routers. Its user interface – LuCi7 – exposes some of its libraries
and functions to external applications through a JSON-RPC API.8
To retrieve the list of all connected devices, an HTTP request is sent to the router
(Listing 17.1):
1 Method: POST
URL: http://router/cgi-bin/luci/rpc/sys?auth=
EBAE1814FA625E73CA0514004428D64A
3 Content-type: application/json
Content: {"jsonrpc": "2.0", "method": "net.arptable", "id":
1}
Listing 17.1 Example of an authenticated POST command to retrieve the list of devices connected
to the router from LuCi
This request will return the list of devices connected to the router by calling the
RPC method net.arptable. Listing 17.2 shows a typical message returned by
this call:
{"id":1,"jsonrpc":"2.0","result":[
2 {"Flags":"0x2","HW type":"0x1","Device":"br-lan","Mask
":"*","HW address":"00:E0:4C:45:57:EF","IP address
":"192.168.1.114"},
{"Flags":"0x2","HW type":"0x1","Device":"br-lan","Mask
":"*","HW address":"00:1C:B3:25:F6:9B","IP address
":"192.168.1.149"},
4 {"Flags":"0x2","HW type":"0x1","Device":"eth0.1","Mask
":"*","HW address":"00:0D:66:22:38:01","IP address
":"89.211.57.1"}]}
Listing 17.2 Example device listing response from LuCi
The response includes a list of the IP addresses of all the physical devices
connected to the router together with additional useful information. Once a list
of the IP addresses of new devices that have just connected is retrieved by a
proxy, the root page of each device is parsed by the Discovery Service using the
procedure described in the next section (by default, the root page should be located
at http://[IP address]:80/).
Resource Discovery
Once a new device has been connected to the network, the second step in the dis-
covery procedure (resource discovery) is carried out to retrieve various information
about the device (functions/services, description, etc.) and make this information
7
http://luci.subsignal.org.
8
The current version of the LuCi is not RESTful, but as it is an open source project, the RESTful
equivalent of this procedure can be easily implemented.
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 393
9
http://microformats.org/2010/07/08/microformats-org-at-5-hcards-rich-snippets.
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 395
Querying Service
Querying for resources within the scope of specific locations (such as “find
all printers in this room”) is a central feature of any infrastructure for smart
devices. InfraWoT enables such queries using various parameters such as the name
of resources, their description, or the RESTful operations and parameters they
accept. Additionally, InfraWoT defines several query types that encapsulate scoping
information (i.e. where to search for resources). The handling of a search request
is thus a two-step procedure that consists of first routing a query to the most
appropriate gateway (e.g., the location proxy responsible for a specific building or a
certain room) and second triggering it there to return the discovered resources.
A client may submit a query by sending an HTTP POST request to the /query
endpoint of a proxy that contains a description of the query, either as a JSON-
encoded string or using a collection of form parameters. Internally, queries are
represented as JSON-serializable Java objects that contain (as mandatory parame-
ters) an ID, the URL of the proxy that initiated the query and their type. Additionally,
a query may contain an arbitrary amount of (optional) parameters that are added
to the JSON representation when serialized. Such an open design facilitates
upgrade and maintenance of InfraWoT (for instance queries could carry piggy-
back structural information). HTTP responses to client queries can be delivered in
multiple different formats, depending on the HTTP Accept-header specified in
the request (usually JSON/XML in queries from another node/application, HTML
in queries from a browser).
In principle, proxies should enable querying for all parameters that occur in
the internal representation of resources. Our implementation is currently limited
to those parameters that are most valuable for clients of the infrastructure. A client
may search for resources using the following query types:
• Keyword Queries. Keyword-based search has become – thanks to the popularity
of Web search engines – the most intuitive query format for many users.
Structured queries (i.e., classical database queries) are quite complex for humans,
who would rather provide textual information about the object in demand, and
let the querying mechanism carry out the interpretation of this data. InfraWoT
supports simple keyword-based querying by matching the provided keywords
with the multiple properties and descriptions of every device in the database.
• UUID Queries. Particularly useful for machine–machine interaction, using the
unique identifier of a device is needed when an application wants to use the in-
frastructure to interact with the same specific device over and over again. To
humans, UUID queries are only of limited use because of the numeric format of
device IDs.
• Name Queries. These queries enable clients to search for resources by their name
and thus represent the human-useable version of UUID Queries.
• REST Service Queries. Matching resources according to the RESTful services
they offer is a key enabler for machine–machine interaction. As the devices
we have enabled for the Web of Things implement the hRESTS Microformat,
396 V. Trifa et al.
Infrastructure Service
The Infrastructure Service is used to initialize the tree structure at startup time and
ensures that the correct structure is maintained during operation. In particular, this
service allows the overall structure to recover from node failures and eventually re-
establish the initial tree configuration (self-stabilization). After the initial setup, all
gateways initialize their Infrastructure Service bundles which start the registration
process with their assigned parents by sending an HTTP POST request that includes
their own URI. Every gateway that receives such a request forwards the received
URI to the Discovery Service which adds the respective gateway as a new child
node.
Furthermore, the Infrastructure Service is responsible for attaching new sub-
resources (i.e., other proxies or devices) found by the Discovery Service or
registered manually. Any resource encountered and analyzed by the Discovery
Service is passed to the Infrastructure Service which uses the resource’s hierarchical
location information to determine whether to attach it to the current proxy or to send
it to a more appropriate gateway. In the latter case, the infrastructure takes care of
routing that resource to the proxy whose hierarchical location corresponds best to
the resource’s (cf. Fig. 17.5). If a registering resource does not provide location
information within its Web representation, the Discovery Service automatically
assigns the location of the proxy itself.
Finally, it acts as garbage collector by regularly contacting the sub-resources and
removing them from InfraWoT when they become unavailable. The Infrastructure
Service starts two threads that regularly contact the parent node, all registered
children nodes, and all attached resources. If the connection to any of these resources
is lost, the corresponding entity gets black-listed and will be removed if contact
cannot be re-established after a timeout period.
The Web Interface Service enables to access the infrastructure and the various
resources connected to InfraWoT using only RESTful requests. In particular, the
Web Interface Service enables the RESTful configuration of InfraWoT location
proxies. We now briefly describe the individual endpoints of the InfraWoT Web
interface and their functionalities:
17 Leveraging the Web for a Distributed Location-aware Infrastructure for the Real... 397
Fig. 17.5 Infrastructure-assisted discovery: any device can POST its root URI (that contains
semantic information about itself) to any node in InfraWoT. If the optional location is known,
the registering in routed to the node corresponding to the location specified
The root of any gateway (“/”) provides general information on the current
proxy (name, hierarchical location, connected sub-nodes, attached resources, etc.).
From the root, one can access four different sub-resources (in addition to /query
described in “Querying Service”):
The /locations resource represents a list of all attached location proxies.
Child nodes may send HTTP POST requests to this address to be registered by the
proxy. The HTML representation of this resource can be used to navigate (browse)
the infrastructure. The individual gateways registered to any node are represented as
child resources of the /locations resource, which can also be used to delete
child nodes. For instance, to remove the gateway with UUID ID32, an HTTP
DELETE request should be sent to the resource /locations/ID32.
The /resources resource represents a list of all sub-resources attached to the
current gateway. Similar to the /locations resource, Web of Things resources
may send HTTP POST requests to this resource to be registered by the gateway.
Likewise, these resources are represented as child resources of the /resources
resource and can be interacted with via requests to their respective endpoint within
the local gateway.
The /infrastructure is mainly used internally by the InfraWoT software
to send and receive maintenance information. One of its sub-resources, though,
plays an important part in the fully Web-based configuration system of InfraWoT
that enables clients to configure a proxy by sending HTTP POST requests to
its configuration interface at /infrastructure/configuration. When a
client POSTs a string of data to this endpoint, the proxy relays that data to the
Discovery Service to retrieve the resource encoded in the transmission and applies
that information to its own representation. Although the currently preferred way
398 V. Trifa et al.
Discussion
Acknowledgments The authors would like to thank Vlatko Davidovski for his contribution to the
design and implementation of the discovery procedure.
References
Abowd, G.D., Mynatt, E.D.: Charting past, present, and future research in ubiquitous computing.
ACM Trans. Comput.-Hum. Interact. 7(1), 29–58 (2000)
Bolliger, P.: Redpin – adaptive, zero-configuration indoor localization through user collaboration.
In: Workshop on Mobile Entity Localization and Tracking in GPS-less Environment Comput-
ing and Communication Systems (MELT), San Francisco (2008)
Fielding, R.T.: Architectural Styles and the Design of Network-based Software Architectures.
Ph.D. thesis, University of California, Irvine (2000)
Fielding, R.T., Taylor, R.N.: Principled design of the modern web architecture. ACM Trans.
Internet Techn. 2(2), 115–150 (2002)
Guinard, D., Trifa, V.: Towards the web of things: web mashups for embedded devices. In:
Workshop on Mashups, Enterprise Mashups and Lightweight Composition on the Web (MEM
2009), in proceedings of WWW (International World Wide Web Conferences), Madrid, Spain
(2009)
Guinard, D., Trifa, V., Wilde, E.: A resource oriented architecture for the web of things. In:
Proceedings of IoT 2010 (IEEE International Conference on the Internet of Things). Tokyo,
Japan (2010)
Jiang, C., Steenkiste, P.: A hybrid location model with a computable location identifier for
ubiquitous computing. In: Proceedings of the 4th International Conference on Ubiquitous
Computing, pp. 246–263. Springer-Verlag, Gnöteborg, Sweden (2002). URL http://
portal.acm.org/citation.cfm?id=741480
400 V. Trifa et al.
Trifa, V., Guinard, D., Bolliger, P., Wieland, S.: Design of a web-based distributed location-aware
infrastructure for mobile devices. In: Proceedings of the First IEEE International Workshop on
the Web of Things (WOT2010), pp. 714–719. Mannheim, Germany (2010)
Trifa, V., Wieland, S., Guinard, D., Bohnert, T.M.: Design and implementation of a gateway for
web-based interaction and management of embedded devices. In: Proceedings of the 2nd
International Workshop on Sensor Network Engineering (IWSNE’09). Marina del Rey, CA,
USA (2009)
Wilde, E., Kofahl, M.: The locative Web. In: Proceedings of the First International Workshop on
Location and the Web, pp. 1–8. ACM, Beijing, China (2008). DOI 10.1145/1367798.1367800
Chapter 18
RESTful Service Architectures for Pervasive
Networking Environments
Abstract Computing facilities are an essential part of the fabric of our society, and
an ever-increasing number of computing devices is deployed within the environment
in which we live. The vision of pervasive computing is becoming real. To exploit
the opportunities offered by pervasiveness, we need to revisit the classic software
development methods to meet new requirements: (1) pervasive applications should
be able to dynamically configure themselves, also benefiting from third-party
functionalities discovered at run time and (2) pervasive applications should be aware
of, and resilient to, environmental changes. In this chapter we focus on the software
architecture, with the goal of facilitating both the development and the run-time
adaptation of pervasive applications. More specifically we investigate the adoption
of the REST architectural style to deal with pervasive environment issues. Indeed,
we believe that, although REST has been introduced by observing and analyzing the
structure of the Internet, its field of applicability is not restricted to it. The chapter
also illustrates a proof-of-concept example, and then discusses the advantages of
choosing REST over other styles in pervasive environments.
Introduction
The Internet evolution is moving fast from “sharing” to “co-creating”. The clear
distinction between content producer and consumer roles, which characterized the
Internet so far, is blurring towards a generic “prosumer” role that acts indistinguish-
ably as both producer and consumer (Papadimitriou 2009). Hence, a “prosumer”
is any active participant in a business, information, or social computing process.
When prosumers are integrated with the computational environment and available
anytime and anywhere, they are generically denoted as “things”. Likewise, the term
M. Caporuscio ()
Politecnico di Milano, Piazza Leonardo, Da Vinci 32, 20133 Milano, Italy
e-mail: [email protected]
Internet of Things is also often used. Due to the multitude of possible different
“things” available within the environment, applications require knowledge and
cognitive intelligence in order to discover, recognize, and process such a huge
amount of heterogeneous information. “Things” provide services to other “things”.
Furthermore, it is possible to retrieve them, interact with them and change their state,
and compose them to build composite “things”, thus creating an Internet of Services.
The above concepts of prosumer, internet of things and internet of services
underlie the Future Internet vision (Papadimitriou 2009), which in turn rests on the
future communication and computational infrastructure. We will be virtually con-
nected through heterogeneous means, with invisible computing devices pervading
the environments (Saha and Mukherjee 2003). Such environments, referred to as
pervasive networking environments, will be composed as spontaneous aggregation
of heterogeneous and independent devices, which do not rely on predetermined
networking infrastructures.
In pervasive networking environments applications emerge from compositions
of the resources (the “things”) available in the environment at a given time. Indeed,
pervasive applications are characterized by a highly dynamic software architecture
where both the resources that are part of the architecture and their interconnections
may change dynamically, while applications are running. As an example, because of
mobility, new things may become available dynamically, while others may suddenly
disappear.
In order to face the extreme flexibility that characterizes pervasive environments,
applications must support adaptive and evolutionary situation-aware behaviors.
Adaptation refers to the ability to self-react to environmental changes to keep
satisfying the requirements, whereas evolution refers to the ability of satisfying new
or different requirements.
In order to be self-adaptable and easily evolvable, applications should exploit
design models that support loose coupling, flexibility, genericity, and dynamicity.
Different architectural styles and coordination mechanisms have been proposed to
deal with, and reason about, distributed applications. For example, the procedural
style, where stateless components interact via remote procedure call, or the object
oriented style, where stateful components interact via messages. Or the service-
oriented style, where functional or object-oriented components are not directly
bound, but rather the binding may be achieved dynamically after a discovery
procedure.
This chapter exploits the REpresentational State Transfer (REST) style to achieve
adaptation and evolution in the context of pervasive networking environment. REST
has demonstrated to be a well-suited design abstraction to deal with flexibility,
genericity and dynamism (Fielding 2000), which are inherent properties of the
Internet. In fact, since networked software applications are conveniently abstracted
as autonomous loosely-coupled resources, they can be dynamically discovered and
accessed at run time (e.g., by means of search engines), as well as combined on-the-
fly to accomplish complex tasks (e.g., mashups).
The standards available for the WEB support quite effective technologies target-
ing the Internet domain. However, supporting WEB resource access in pervasive
18 RESTful Service Architectures for Pervasive Networking Environments 403
Background
Research has been focusing for more than a decade on adaptive and distributed
systems. Such systems have been investigated from many points of view and at
different levels of abstraction. Particular attention has been devoted to architectural
aspects, i.e., how to architect distributed systems to make them amenable to
changes (Cheng et al. 2009). In this area, research has been mainly following
two trends. On the one hand, it focused on the properties to be met by software
architectures to enable applications to adapt to run-time changes. On the other,
research focused on high-level models of architecture that can be kept alive at run
time to support adaptation.
Since our work builds on top of both the research lines, in this section we will
give a brief review of the main architectural styles emerged during the past decade
and then we will go through the work on run-time models.
Architectural Styles
Many different architectural styles1 have been proposed to deal with, and reason
about, distributed systems. They can be classified according to several dimensions:
(1) the type of coupling imposed by the model on entities; (2) the degree of
flexibility, that is the ability of the specific model to deal with the run-time growth
1
We also use the terms architectural model and design model interchangeably throughout the paper.
404 M. Caporuscio et al.
of the application in terms of involved components; (3) the degree of genericity, that
is the ability to accommodate heterogeneous and unforeseen functionalities into the
running application; (4) the kind of dynamism, that is the possibility to rearrange
the application in terms of binding, as well as adding new functionality discovered
at run time.
Table 18.1 classifies the main architectural models in terms of their characteris-
tics with respect to the pervasive networking issues.
The oldest design model for distributed architectures is based on functional
distributed components that are accessed in a synchronous way through Remote
Procedure Call (RPC). This supports a client–server style, where: (1) client and
server are tightly coupled, (2) adding/removing functions strongly affects the
behavior of the overall network-based system, (3) function signatures are strict, and
(4) binding between entities is generally statically defined and cannot vary (new
functions cannot be discovered at run time).
Object Oriented architectures support distributed objects, and provide higher-
level abstractions by grouping functions (methods) that manipulate the same object
and encapsulating (and hiding) state information. The type of interaction among
objects, however, is synchronous, as for the previous case. In summary: (1) interact-
ing objects are still tightly-coupled in a client–server fashion, (2) adding/removing
entities as the system is running is hard to support, (3) interfaces are specified via
strict method signatures, and (4) once a reference to a remote object is set, normally
it does not change at run time, and there is no predefined way of making objects
discoverable (i.e., supporting this feature requires for additional ad-hoc effort).
Service Oriented Architecture (SOA) is a further step from the previous two cases
because networked entities are abstracted as autonomous software services that can
be accessed without knowledge of their underlying technologies. In addition, SOA
opens the way to dynamic binding through dynamic discovery. In summary: (1)
services are independent and loosely-coupled entities, (2) services can be easily
added/removed and accessed, irrespective of their base technology, (3) service
access is regulated by means of well-defined interfaces, and (4) binding between
services can in principle be dynamically established at run time (although in existing
SOA application this is not common practice), and new entities may be discovered
and bound dynamically.
2
This feature is conceptually feasible, although several existing instantiations of the architectural
style do not support it.
18 RESTful Service Architectures for Pervasive Networking Environments 405
Relies on 1
Manipulates
Environment 1 1 1 1 1
Queries Decision Maker Interprets Actuator
1..* Run-Time Model
Requirement 1 1
Updates Queries 1
1 1
1..*
1 Architecture 1 1 Current
1 Monitor Updates
Relies on Run-time Model Application
Manipulates
1 1..*
Senses Contains Application
1
0..* 1 1
Sensor Contains Environment External Service/
0..* Component
REpresentational State Transfer (REST) differs from all the previous models in
the way distributed entities are accessed and in the way their semantics is captured.
REST entities are abstracted as autonomous and univocally addressable resources,
which have a uniform interface consisting of few well-defined operations. In all
previous cases, entities have different and rich interfaces, through which designers
capture the semantic differences of the various entities. In REST, all entities have
the same interface. Semantic information is attached separately to the identification
mechanism that allows entities to be accessed. In addition, interaction with REST
entities is stateless. In summary: (1) resources are independent and loosely-coupled
entities, (2) resources can be easily added, removed and accessed, irrespective of
their underlying technology, (3) resource access is regulated by means of a uniform
interface, and (4) binding between resources is dynamically established at run time
even though, in general, there is no standard way to discover and access them.
However, this might be achieved by means of additional support.
Model to reason about the current state of the application and to devise a new
abstract architecture that meets the new Requirements. The Actuator is in charge of
translating the solution into an architecture and keeping the Architecture Run-time
Model synchronized with the new Architecture. Adopting a suitable architectural
style for describing the Architecture Run-time Model eases the decision maker’s
reasoning process (i.e., rules and constraints are well-known and predefined) and
provides the actuator with a clear set of actions (i.e., actions are narrowed by the
style’s constraints) that can be performed. This also guarantees that newly devised
solutions are compliant with the change by construction.
As for adaptation, an application must be aware of the environment it is working
in. This is modeled by the Environment entity, which contains the applications
running in an environment. An Application is described as an aggregation of
the description of its architecture and of the external services or components it
interacts with. The conceptual model includes the Sensors that abstract the physical
context. The Decision Maker accesses the Environment Run-time Model and the
Architecture Run-time Model to decide about the possible adaptive changes that
need to be made to the architecture in response to changes in the environment. As
opposed to evolution, adaptation is mostly achieved in a self-managed manner by
the Actuator.
Why REST?
The concept of a Resource plays a pivotal role in the REST architectural style.
In fact, it can be seen as a model of any object in the world (i.e., “things”) with a
clear semantics that cannot change over its lifetime. An application built according
to the REST style is typically made of a set of interacting resources. An application
built according to the REST architectural style is said to be “RESTful” if it does
respect the four basic principles introduced by Fielding (2000) and then elaborated
by Richardson and Ruby (2007): Addressability, Statelessness, Connectedness,
Uniformity. These principles, along with the design model they induce on the
application, seem to naturally apply to pervasive environments.
Addressability requires resources to have at least one URI. This RESTful
applications to be found and consumed, as well as their constituent resources to be
accessed and manipulated. The possibility to retrieve and use constituent resources
enables prosumers to opportunistically reuse parts of a RESTful application in ways
the original designer has not foreseen (Edwards et al. 2009).
The statelessness principle makes REST very appealing to pervasive systems. It
establishes that the state of the interaction between a user and a RESTful application
must always reside on the user side.
Since the state of the interaction is kept by the user, computations can be
suspended and resumed (without losing data) at any point between the successful
completion of an operation and the beginning of the next one. Indeed, using two
different but equivalent resources,3 will produce the same results. This is important
in a pervasive environment since a computation, hindered by the departure of a
resource, can, in principle, be resumed whenever an equivalent resource is available.
Other advantages – for non-ephemeral resources – are contents “cacheability” and
the possibility of load balancing through resource cloning. Hence, statelessness
enhances (1) decoupling of interacting resources, (2) flexibility of the model, since
it allows for easily rearranging the application at run time and, (3) scalability, by
exploiting resource caching and replication. The price to pay derives from the need
for an increased network capacity because the whole state of the interaction must be
transferred at each request.
3
We define two resources as equivalent iff they have the same behavior and adopt the same
encoding for their representations.
408 M. Caporuscio et al.
REST technologies rely on (1) the stability of the underlying communication envi-
ronment and (2) tightly-coupled synchronous interaction protocols only. Pervasive
environments, instead, require to (1) cope with an ever-changing communication
infrastructure because devices join and leave the environment dynamically (Roman
et al. 2000) and (2) to support loosely-coupled asynchronous coordination mecha-
nisms (Huang and Garcia-Molina 2001).
This section investigates how the REST architectural style should be modified to
cope with pervasive environments, and introduces the Pervasive-REST (P-REST)
design model. Indeed, to make REST pervasive we need to adapt the different
levels of abstraction, namely the architecture, the coordination model, and the
infrastructure.
As we observed, in pervasive environments and, more generally, in systems
envisioned for the Future Internet the role of “prosumer” will be central. Further-
more, such a prosumer role might be played by any “thing” within the environment.
Hence, we foresee the necessity of departing from usual REST description of the
world, made in terms of user agents that consume resources from origin servers
18 RESTful Service Architectures for Pervasive Networking Environments 409
(see “Why REST?”). Rather, the P-REST architectural style promotes the use
of Resource as first-class object that fulfills all roles. This means that, at the
architectural level, we remove the distinction among actors, and thus we model
entities in the environment as resources, which can act both as clients and servers.
To support coordination among resources, we extend the traditional request/re-
sponse REST mechanism through primitives that must be supported by an un-
derlying middleware layer. First, we assume that a Lookup service is provided,
which enables the discovery of new resources at run time. This is needed because
resources may join and leave the system dynamically. Once the resource is found,
REST operations may be used to interact with it in a point-to-point fashion.
The Lookup service can be implemented in several ways [e.g., using semantic
information (Mokhtar et al. 2006), leveraging standard protocols (Romero et al.
2010)]. However, we do not rely on any specific implementation since we are
focusing on the study of the design model.
The Lookup service yields the URI of the retrieved resource. Since resource
locations may change as a result of both logical mobility (e.g., the migration of a
resource from a device to another) and physical mobility (e.g., resources temporarily
or permanently exiting the environment), a service is needed to maintain the maps
between resource URIs and their actual location. Such service plays the role of a
distributed Domain Name System (DNS) (Network Working Group 2003).
In addition, we adopt a coordination style based on the Observer pattern, as
advocated in the Asynchronous-REST (A-REST) proposal described by Khare
and Taylor (2004). This allows a resource to express its interest in state changes
occurring in another resource by issuing an Observe operation. The observed re-
source can then Notify the observers when a change occurs. In this case, coordination
is achieved via messages exchanged among resources.
Figure 18.3 summarizes the modification we made to the REST style. Resources
directly interact with each other to exchange their representations (denoted by in
410 M. Caporuscio et al.
the figure). Referring to Fig. 18.3, both Resource1 and Resource2 observe Resource3
(messages ).a When a change occurs in Resource3 , it notifies (message ) b the
observer resources. Once received such a notification, Resource1 issues a request
for the Resource3 and obtains as a result the representation 3 (message ).
c Note
that, while observe/notify interactions take place through the point-to-multipoint
connector (represented as a cube), REST operations exploit point-to-point connector
(represented as a cylinder). All the resources exploit both the Lookup operation to
discover the needed resources, and the DNS service to translate URIs into physical
addresses.
P-REST Meta-model
Along with the P-REST architectural style introduced above, we also define a
P-REST meta-model (depicted in Fig. 18.4) describing the pervasive environment,
the resources within the environment, and the relations among resources that define
a pervasive application.
The Environment entity defines the whole distributed and pervasive environ-
ment as a resource container, which provides infrastructural facilities. In particular,
it provides three operations that can be invoked by a resource: (1) OBSERVE,
which declares its interest in the changes occurring in a resource identified by a
given URI, (2) NOTIFY, which allows the observed resource to notify observers
18 RESTful Service Architectures for Pervasive Networking Environments 411
about the occurred changes, and (3) LOOKUP, which implements the distributed
lookup service. These operations are the straightforward implementations of both
the A-REST principle and of the lookup service, respectively.
Since Resource is a unifying first-class object, the P-REST meta-model
describes every software artifact within the environment as a Resource. According
to the Uniformity principle (see “Why REST?”), each resource implements a set
of well-defined operations, namely PUT, DELETE, POST, GET, and INSPECT.
The PUT operation updates the resource’s internal state according to the new
representation passed as parameter. The DELETE operation results in the deletion of
the resource. The POST operation may be seen as a remote invocation of a function,
which takes the representation enclosed in the request as input. The actual action
performed by POST is determined by the resource providing it and depends on both
the input representation and the resource’s internal state. The semantics of the POST
operation is different for different resources. This differs from the other operations
whose semantics is always the same for every resource. Even if the semantics of
POST is not defined by the architectural style, it is still constrained. Indeed, it
can have only one semantics per-resource, and thus, overloading is not allowed.
The GET implements a read-only operation that returns a representation of the
resource. The INSPECT operation allows for retrieving meta-information about the
resource.
REST operations can be safe and/or idempotent. An operation is considered safe
if it does not generate side-effects on the internal state, whereas it is idempotent
if the side-effects of N > 0 identical requests is the same as for a single request.
GET and INSPECT operations are both idempotent and safe, PUT and DELETE
operations are not safe but they are idempotent, whereas for the POST operation
nothing is guaranteed for its behavior.
The REST architectural style does not provide any means to describe the
semantics of resources, which is rather embedded in the URIs of resources or
delegated to natural language descriptions. Instead, P-REST assumes that every
resource is provided with meta-information concerning both its static and dynamic
properties. As an example, for a resource representing a theater, the semantic
description includes the total number of seats (a static property) as well as the
number of free seats (a dynamic property). Indeed, P-REST promotes resource’s
semantics as first-class concern by explicitly introducing the Description entity.
Specifically, Description describes both functional and non-functional properties of
a resource, possibly relying on a common ontology that captures the knowledge
shared by the entire pervasive environment (Berners-Lee et al. 2001). Description
can also define which operations, among the available ones, are allowed or not –
e.g., DELETE could be forbidden on a specific resource. Moreover, Description
entities are also used to achieve dynamism (see Table 18.1). In fact, Descriptions
support the implementation of the lookup service by exploiting efficient algorithms
for distributed semantic discovery (e.g., Mokhtar et al. 2006), thus enabling de facto
run-time resource discovery. As introduced above, Descriptions are retrieved via
the INSPECT operation. Referring to the HTTP uniform interface that underlies
412 M. Caporuscio et al.
REST, INSPECT operation encapsulates both HEAD and OPTION operations and
goes further by providing also the functional and non-functional specification of the
target resource.
At run time, resources have their own internal state, which should be kept
private and not directly accessible by other resources. The Representation
entity overcomes such an issue by exposing a specific rendering of its internal
state rather then the state itself. Hence, a Representation is a complete snapshot
of the internal state, which is made available for third-party use. Every resource
is associated with at least one representation, and multiple representations might
be available for a given resource. This is particularly useful when dealing with
heterogeneous environments in which several different data encodings are needed.
A resource’s representation can be retrieved by means of the GET operation, which
can also implement a negotiation algorithm to understand which is the most suitable
representation to return.
As introduced in “Why REST?”, addressability states that every resource must
be identified by means of an URI. Hence, in P-REST, every Resource is bound to
at least one Concrete URI (CURI), and multiple CURI can refer to the same
resource. Resources without any CURI are forbidden, as well as CURIs referencing
multiple resources. However, P-REST enhances the concept of URI by introducing
the Abstract URI (AURI) entity. Specifically, an AURI is a URI that identifies a
group of resources. Such groups are formed by imposing constraints on resource
descriptions (e.g., all the resources implementing the same functionality). The
scheme used to build AURIs is completely compatible with the one used for CURI,
thus they can be used interchangeably. Moreover AURIs are typically created at run
time by exploiting the LOOKUP operation to find resources that must be grouped.
This addition to the standard concept of URI is meant to support a wider range
of communication paradigm. Indeed, using CURI allows for establishing point-to-
point communication while using AURI allows for multicast communication. The
latter can be useful, for instance, to retrieve the values of an entire class of sensors
(e.g., humidity sensors scattered in a vineyard).
Resources can be used as building-blocks for composing complex functionalities.
A Composition is still a resource that can, in turn, be used as a building-block
by another composition. REST naturally allows for two types of compositions:
mashup and work-flow. A mashup is a resource implemented by exploiting the
functionalities provided by third-party resources. In this case, an interested client
always interacts with the mashup, which in turn decomposes client’s requests
into sub-requests and routes them to the remote resources. Responses are then
aggregated within the mashup and the result is finally returned to the client. On
the other hand, a composition built as work-flow directly leverages the HATEOAS
principle. In this case, an interested client starts interacting with the main resource
and then proceeds by interacting with the resources that are discovered/created step-
by-step as result of each single interaction.
Resources involved in a composition are handled by a Composition Logic,
which is in charge of gathering resources together and, if they were not designed
to interact with each other, of satisfying possible incompatibilities (e.g., handling
18 RESTful Service Architectures for Pervasive Networking Environments 413
Naming
System
Coordination Point-to-Point Point-to-Multipoint
4
Clearly, this scenario requires for additional mechanisms able to foresee whether the device leaves
the environment.
18 RESTful Service Architectures for Pervasive Networking Environments 415
each device within the pervasive environment hosts one container that, just like a
Web server, handles both the life-cycle and the provision of its resources. However,
unlikely Web servers, containers provide the primitives for both creating resources
and migrating resources among containers (i.e., MOVE, CREATE). Their behavior,
however, can be customized in order to achieve specific behaviors. For example, the
CREATE operation can be made aware about the current load of the local container
and actually allocate a resource in another similar container. As a final remark, the
physical address provided by the DNS for a specific URI actually is the container’s
one. Indeed, a container receives all its contained resources’ requests and dispatches
them to the right resource based on the CURI.
Using the programming abstractions provided by the Abstraction layer, a
P-RESTful application is then built as a resource that relies on other resources to
meet its requirements. Specifically, the interactions between resources is specified
by means of a composition language, which allows for composing and managing
sets of resources. PRIME offers primitives to modify the composition logic at run
tim, thus enabling architectural reconfiguration (i.e., ADD, REMOVE, SUBSTITUTE
and REWIRE). We will account for these operations in “P-RESTful Self-adaptive
Systems.”
The PRIME APIs exploit a functional programming paradigm, which naturally
achieves resource composition as the sequential application of functions. Functions
are bound each other by accepting and producing immutable data structures.
Immutable data structures map to resources representation, and functions are
the operations exposed by resources. Through a functional language, resource
compositions amounts to wiring the output of a function (i.e., operation) to the input
(i.e., resource representation) of the next function. Such a functional composition
can also be applied to functions that are, in turn, implemented as compositions.
Thus the handling of arbitrarily complex compositions is easy and intuitive.
It is worth to note that, the abstractions provided by PRIME recall the ones
introduced by CREST (Erenkrantz et al. 2007). The difference between the two
approaches lies in the fact that PRIME provides such operations as infrastructural
facilities, whereas in CREST resource mobility is promoted to a design principle.
For such a reason we keep containers and their operations outside the P-REST meta-
model. Indeed, a designer who wants to instantiate the P-REST meta-model should
not be concerned with problems related to the deployment and distribution of the
application.
We argue that self-adaptive applications for pervasive systems may benefit from the
adoption of the P-REST design model. To prove this, we show how the conceptual
model for self-adaptive systems (Background) can be implemented by means of the
P-REST meta-model (REST for Pervasive Systems), and show how the mechanisms
provided by PRIME make P-RESTful application effective.
416 M. Caporuscio et al.
Both the conceptual model (Fig. 18.2) and the P-REST meta-model (Fig. 18.4)
contain an environment entity. While in the conceptual model the environment is
populated by generic software artifacts, in P-REST all the entities contained in the
environment are modeled as a resource.
As shown in Fig. 18.2, the conceptual model revolves around the architecture
run-time model and the environment run-time model. In P-REST, the architecture
of the application is rendered by means of the set of resources it is composed of
and the composition logic that orchestrates them. The type of composition used
(i.e., workflow or mashup) depends on the specific functional requirements of the
application. The environment run-time model is a composition of resources defined
as a mashup. The corresponding composition logic is in charge of realizing the
mashup by querying component resources and aggregating the results of such
queries. Thus, this composition logic plays the role of the monitor.
Here we are not concerned with investigating how a decision maker might exploit
the run-time models to adapt/evolve the system. Rather we want to show which
mechanisms, enabled by P-REST, can be leveraged by the actuator to modify the
running system according to decision maker’s instructions. As reported by Oreizy
et al. (1998), an actuator operating at the software architecture level should support
two types of change: one affecting the components, namely addition, removal and
substitution, and one affecting the connectors, namely rewiring.
The problem of dynamically deploying and/or removing a component from
an assembly has been repeatedly tackled in literature (Kramer and Magee 1990;
Vandewoude et al. 2007). Such solutions are often computationally heavy and
require expensive coordination mechanisms. Moreover, preserving the whole dis-
tributed state is often very difficult since the internal state of a component is not
always directly accessible. To make the problem easier, several architectural styles
have been introduced. According to P-REST, adding a new resource is trivial and
requires two simple steps: (1) deploy the new resource within the environment, and
(2) make it visible by disseminating its URI. Once these steps are performed, the
resource is immediately able to receive and process incoming requests.
On the other hand, removing a component can in general cause the loss of some
part of the distributed state. P-REST, instead, works around this problem because
of the stateless nature of the interactions. That is, the removed resource carries
away only its internal state, thus the ongoing computations it is involved in are
not jeopardized.
Substituting a component with another one cannot be simply accomplished by
composing removal and addition operations. Specifically, the issue here concerns
how to properly initialize the substituting component with the internal state of the
substituted one. Indeed, due to information hiding it is not always possible (and
not even advisable) to directly access the internal state of a component. Clearly the
component can always expose part of its internal state but there is no guarantee about
the completeness of the information provided. On the contrary, P-REST imposes
that a resource’s representation is a possible rendering of its internal state, which
is always retrievable by exploiting the GET operation, eventhough the resource is
18 RESTful Service Architectures for Pervasive Networking Environments 417
The first step of the operation retrieves the reference to the container of the
old resource (i.e., the resource to be substituted). As we have already highlighted,
the physical address of a container coincides with the physical address of all the
resources contained in it. Thus, the resolve operation provided by the DNS can be
exploited to retrieve, given a CURI, the physical address of the container managing
the resource identified by CURI. Once retrieved, such a reference is used to access
the operations offered by the container for monitoring and regulating the activities of
the contained resources (i.e., their life-cycle). Line 3 instructs the container holding
the old resource to buffer all the incoming requests directed to oldr while the
substitution is taking place. As a next step, the substitute operation executes
a blocking operation to wait for oldr to finish processing all the requests that
are still ongoing (line 4). Now the internal state of oldr can be retrieved safely
through its uniform interface (line 5) and used to initialize the new resource (newr)
using a PUT operation (line 6). As stated above, a composition logic knows all its
composing resources (through their CURIs), and we are assuming their CURIs to be
stored in an instance of a data type called components. The instruction on line
7 substitutes the old CURI with the new one, so that the latter will always be used
from now on instead of the former. Lines 8–10 retrieve the buffer of blocked requests
addressed to oldr, and let newr consume them. It is important to remark that since
the state of the new resource is overwritten by the substitute routine, it is good
practice to create the new resource from scratch in order to avoid unpredictable
side-effects. Indeed, if the newly inserted resource is used concurrently by other
418 M. Caporuscio et al.
In this section we describe a small case study, which is inspired by the 2015 Milan
Universal Exposition (EXPO2015). We envision a city-wide pervasive environment
where people, equipped with mobile devices embedding networking facilities (e.g.,
PDAs, smart-phones), are interconnected with each other to share information and
functionalities. Any attendee may be a prosumer, acting as either participant or
organizer of unexpected events.
Specifically, suppose that Carl wants to organize and promote his own BarCamp.
A BarCamp5 is an ad-hoc and spontaneous event with discussions and demos where
participants, who are the main actors of the event, interact with each other sharing
knowledge about a specific topic. To bootstrap his BarCamp, Carl has to (1) choose
the topic and advertise the event in order to gather potential participants, (2) find and
reserve a free pavilion, and (3) deploy the needed software infrastructure to handle
participants’ registrations.
Hereafter we address the functional design of the BarCamp application, starting
from the identification of the involved resources and their relationships. Figure 18.6
sketches a simplified design of the application where some details are omitted for
simplicity. We represent the Environment as an enclosing container for the resources
instead of representing it as an explicit box and, as a consequence, drawing a
containment relation from every other entities towards it. Also, representations and
descriptions do not appear in the diagram since they are not relevant to our purpose.
5
http://www.barcamp.org/.
18 RESTful Service Architectures for Pervasive Networking Environments 419
Environment
BarCamp Logic
Comp
GET := send(GET, eURI) ≈ BarCamp
send(GET rfURI) Comp Comp Logic
+Type
PUT := send(PUT, rep, rfURI) Context Context Logic
+Topic
DELETE := send(DELETE, eURI); +Seat #
send (DELETE,rfURI) has +GET() has GET := send(GET,
+PUT() +Reservation # pURI) ≈
POST := send(POST,rep,rfURI)
INSPECT := send(INSPECT, eURI) ≈ +DELETE() +GET() send(GET rfURI)
send(INSPECT, rfURI) +INSPECT()
+POST() Environment Run-Time model Monitor
The cornerstone element of the BarCamp application described in Fig. 18.6 is the
BarCamp resource, which is designed as a composition of (1) Event, which carries
information about the event and (2) RegFac, which gathers attendee registrations to
the event.6 The associated composition logic, namely BarCamp Logic, defines the
behavior of the operations exposed by the composite resource. The GET operation
is computed by retrieving the current representation from both Event and RegFac
and joining them (join operations are denoted by the ˚ symbol). The actual result
will be returned as a representation containing information about the event along
with the registrations gathered so far. The PUT operation is directly mapped to the
PUT operation provided by RegFac. The DELETE operation deletes the composite
resource by invoking DELETE on Event and then on RegFac. The POST operation
directly maps to the POST operation provided by RegFac. In this case, the specific
semantics of POST is to create a new registration in the RegFac. The INSPECT
operation is computed by inspecting both Event and RegFac and joining the results.
The Context resource carries environmental data. It exposes only the GET operation
that is computed by the ContextLogic by joining the number of available seats in
the Pavilion and the number of registrations submitted to RegFac.
The application design, shown in Fig. 18.6, is a static description of the applica-
tion and does not take into account deployment concerns, which in turn should be
specified by means of different notation [e.g., UML Deployment Diagrams (Object
Management Group 2010)]. Hence, we assume that resources created by Carl,
namely BarCamp, BarCamp Logic, Event, Context and Context Logic will be
deployed on his PDA. On the other hand, Pavilion and RegFac resources are hosted
by the corresponding pavilion’s infrastructural server.
According to “Background”, in order to address self-adaptation the application
should implement the concepts defined by the conceptual model in Fig. 18.1. The
6
We assume that the software implementing the registration facility is provided by the Exposition
Center’s infrastructure as a downloadable package to foster the organization of spontaneous events.
420 M. Caporuscio et al.
Acknowledgements This research has been Funded by the European Commission, Programme
IDEAS-ERC, Project 227077-SMScom (SMSCom 2008).
422 M. Caporuscio et al.
References
Ben Mokhtar, S., Kaul, A., Georgantas, N., Issarny, V.: Efficient semantic service discovery in
pervasive computing environments. Middleware 2006, pp. 240–259 (2006)
Berners-Lee, T., Hendler, J., Lassila, O.: The Semantic Web. Scientific American (2001)
Caporuscio, M., Funaro, M., Ghezzi, C.: Architectural issues of adaptive pervasive systems. In:
G. Engels, C. Lewerentz, W. Schäfer, A. Schı̈urr, B. Westfechtel (eds.) Graph Transformations
and Model Driven Enginering – Essays Dedicated to Manfred Nagl on the Occasion of his 65th
Birthday, Lecture Notes in Computer Science, vol. 5765, pp. 500–520. Springer (2010)
Cheng, B.H.C., de Lemos, R., Giese, H., Inverardi, P., Magee, J. (eds.): Software Engineering
for Self-Adaptive Systems, Lecture Notes in Computer Science, vol. 5525. Springer, Berlin,
Heidelberg, New York (2009)
Edwards, W.K., Newman, M.W., Sedivy, J.Z., Smith, T.F.: Experiences with recombinant comput-
ing: Exploring ad hoc interoperability in evolving digital networks. ACM Trans. Comput.-Hum.
Interact. 16(1), 1–44 (2009). DOI http://doi.acm.org/10.1145/1502800.1502803
Epifani, I., Ghezzi, C., Mirandola, R., Tamburrelli, G.: Model evolution by run-time parameter
adaptation. In: ICSE ’09, pp. 111–121. IEEE Computer Society, Washington, DC, USA (2009).
DOI http://dx.doi.org/10.1109/ICSE.2009.5070513
Erenkrantz, J.R., Gorlick, M., Suryanarayana, G., Taylor, R.N.: From representations to computa-
tions: the evolution of web architectures. In: ESEC-FSE ’07, pp. 255–264 (2007)
Fielding, R.T.: REST: Architectural styles and the design of network-based software architectures.
Ph.D. thesis, University of California, Irvine (2000)
Huang, Y., Garcia-Molina, H.: Publish/subscribe in a mobile enviroment. In: Proceedings of the
2nd ACM International Workshop on Data Engineering for Wireless and Mobile Access, pp.
27–34 (2001)
Khare, R., Taylor, R.N.: Extending the representational state transfer (rest) architectural style for
decentralized systems. In: ICSE ’04, pp. 428–437. IEEE Computer Society, Washington, DC,
USA (2004)
Kramer, J., Magee, J.: The evolving philosophers problem: Dynamic change management. IEEE
Tran. Soft. Eng. 16(11), 1293–1306 (1990). DOI http://dx.doi.org/10.1109/32.60317
Network Working Group: Role of the Domain Name System (DNS) (2003). RFC3467
Object Management Group: Unified Modeling Langiage Specification (2010). Version 2.3
Oreizy, P., Medvidovic, N., Taylor, R.N.: Architecture-based runtime software evolution. In: ICSE
’98, 1998.
Papadimitriou, D.: Future internet – the cross-etp vision document. http://www.future-internet.eu
(2009). Version 1.0
Richardson, L., Ruby, S.: Restful web services. O’Reilly (2007)
Roman, G.C., Picco, G.P., Murphy, A.L.: Software engineering for mobility: a roadmap. In: FOSE
’00, pp. 241–258. ACM, New York, NY, USA (2000). DOI http://doi.acm.org/10.1145/336512.
336567
Romero, D., Rouvoy, R., Seinturier, L., Carton, P.: Service discovery in ubiquitous feedback control
loops. In: DAIS, pp. 112–125 (2010)
Saha, D., Mukherjee, A.: Pervasive computing: A paradigm for the 21st century. Computer 36(3),
25–31 (2003). DOI http://doi.ieeecomputersociety.org/10.1109/MC.2003.1185214
SMSCom: Self Managing Situated Computing. http://www.erc-smscom.org/ (2008)
Vandewoude, Y., Ebraert, P., Berbers, Y., D’Hondt, T.: Tranquility: A low disruptive alternative
to quiescence for ensuring safe dynamic updates. IEEE Trans. Softw. Eng. 33(12), 856–868
(2007). DOI http://dx.doi.org/10.1109/TSE.2007.70733
Vinoski, S.: Demystifying restful data coupling. IEEE Internet Computing 12(2), 87–90 (2008)
Part VI
REST Research
Chapter 19
On Entities in the Web of Data
Michael Hausenblas
Abstract This chapter aims to explore what “entities” in the Web of Data are. As
a point of departure we examine a number of widely used RESTful Web APIs
in terms of URI space design and hyperlinking support in the offered resource
representations. Based on the insights gained from the API review, we motivate the
concept of an entity as well as its boundaries. Eventually we discuss the relevance of
the entity concept for publishers and consumers of Web data, as well as the impact
on Web data design issues.
However, as this chapter unfolds, we will discover that a somewhat similar problem
exists concerning Web data. When we say Web data in the context of this chapter,
we mean data as found in Web APIs and dataset collections, such as governmental
statistics, eCommerce product data, or media content (such as found in Flickr), with
a particular interest in widely deployed formats, including Atom, JSON, but also
serialisations of the Resource Description Framework (RDF) (Klyne et al. 2004).
Eventually, we are particularly interested in a characteristic of Web data that tells
it apart from centralised data sources (such as relational databases): links between
data items.
M. Hausenblas ()
DERI, National University of Ireland Galway, IDA Business Park, Galway, Ireland
e-mail: [email protected]
Methodology
In the following, we will have a closer look at widely used and popular services that
claim to offer RESTful APIs. The goal is to gain a deeper insight into the actual
deployment status of resource granularity and the degree of hyperlinking support.
In order to assess the before-mentioned aspects, we will examine the following
characteristics of each API:
1. URI space design. In this respect, we are interested in how the API’s URI space is
partitioned: we analyse if all important resources have URIs, how the URI space
is organised and how cool the URIs are.1 For example, they URI space may be
organised in a flat manner or hierarchically.
2. Representations. Concerning the resource representations offered by the API, we
ask if registered media types, such as Atom (Nottingham and Sayre 2005) are
used vs. custom formats. Further, we investigate if alternative representations are
offered via content negotiation or comparable mechanisms (Raman 2006).
3. Hyperlinking. Regarding this aspect we examine if and how hyperlinks are
used. Based on the findings in the previous category we analyse the utilisation
of hyperlinks in the representations served by the API. We ask especially to
which extend they support the discovery of related data items within the site
and potentially outside the API.
The selection of the APIs in the following is based on popularity2 and experi-
ences the author has gained in projects as well as from the interaction with the REST
1
http://http://www.w3.org/Provider/Style/URI.
2
http://http://www.programmableweb.com/apis/directory/1?protocol=REST.
19 On Entities in the Web of Data 427
community. We are well aware of the fact that the review is neither exhaustive nor
definitive, nonetheless it offers an representative insight what is currently available
in terms of RESTful APIs on the Web.
Each of the following sections3 starts out with a table summarising the API char-
acteristics regarding the above aspects and further lists more detailed observations
per API. For the summary table we will use fine-grained if the URI space exposes all
relevant resources and coarse-grained if only few resources are exposed. Note that
our usage of fine-grained vs. coarse-grained differs from the usage typically found in
the literature, where fine-grained refers to object-oriented style and coarse-grained
means document-style interactions with fewer, but more structured documents.
Basecamp
1. URI space design. The API exposes the relevant resources of the domain in a
fine-granular, hackable manner. For example, each to-do list in a project has a
URI.5
2. Representations. A proprietary XML format is used as the main representation;
content negotiation is supported.
3. Hyperlinking. There seems to be no explicit usage (or support) of hyperlinking
in the XML representations.
Delicious
Delicious is a social bookmarking site, mainly dealing with people, bookmarks, and
tags, with a documented API.6
3
The API reviews are presented in alphabetical order.
4
http://http://developer.37signals.com/basecamp/.
5
http://https://lidrc.basecamphq.com/projects/4284964/todo lists.
6
http://http://www.delicious.com/help/api.
428 M. Hausenblas
1. URI space design. Only few of the main resources the API deals with are in fact
exposed, such as posts.7
2. Representations. The API offers a custom XML without content negotiation.
Interestingly, JSON format is offered for certain types of information via a
separate, so called “Feed API”.8
3. Hyperlinking. Although the representations contain hyperlinks (for example,
in the shape of <post href=’http://example.org’>...</post>),
the data items such as people and their bookmarks are not linked.
Facebook is a social network platform, mainly dealing with people, groups, events,
messages, applications, and shared media content (images, videos, etc.) with a
JSON-centric API.9
1. URI space design. All major resources are exposed via human-readable URIs,
like people10 or events.11
2. Representations. The main representation used in the API is JSON (no content
negotiation offered) with an extension mechanism via the OpenGraph protocol12
for integrating external content into the Facebook platform.
3. Hyperlinking. Hyperlinks are used in the representations, however, only
for stating values such as "link": "http://www.facebook.com/
mhausenblas" and not to relate the data items within the platform.
7
http://https://user:[email protected]/v1/posts/get.
8
http://http://www.delicious.com/help/feeds.
9
http://http://developers.facebook.com/docs/api.
10
http://http://graph.facebook.com/mhausenblas/
11
http://http://graph.facebook.com/331218348435/.
12
http://http://developers.facebook.com/docs/opengraph
19 On Entities in the Web of Data 429
Flickr
Flickr is an image and video hosting website, mainly dealing with shared media
content, people, groups, and tags with a so-called “REST API”.13
1. URI space design. The API exposes the main resources, such as photos14 via
distinct URIs, however the method names are explicitly encoded as URI parame-
ters (like ?method=flickr.photos.getInfo), which is considered a bad
practice in the REST community.
2. Representations. Both proprietary XML and JSON are offered, albeit not via
content negotiation but via a parameter (format=json).
3. Hyperlinking. One can find usages of typed hyperlinks in the served representa-
tions (such as <url type="photopage">...</url>, linking a photo to
its page), however, in the general case the data items are connected via literal
values (for example <owner nsid="7278720@N02"... />).
FriendFeed
1. URI space design. All important resources in the API have URIs (for example, a
person’s feed16 ) and follow a logical structure.
2. Representations. The default representation the API offers is JSON, and custom
XML can be obtained (format=json), however not via content negotiation.
3. Hyperlinking. Hyperlinks are used in the provided representations, for ex-
ample to represent the provenance of an entry (a link to a microblog post:
"url": "..."), however, not to provide navigation between data items in
the representations.
13
http://http://www.flickr.com/services/api/request.rest.html.
14
http://http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&photo id=4745449672.
15
http://http://friendfeed.com/api/documentation.
16
http://http://friendfeed-api.com/v2/feed/mhausenblas.
430 M. Hausenblas
GeoNames
1. URI space design. All main resource have dedicated URIs, such as a certain
region.18
2. Representations. The API offers a wide range of representations, including the
two most widely supported XML and JSON (via dedicated URIs, no content
negotiation), but also other formats, such as CSV, RDF/XML, KML and RSS.
3. Hyperlinking. In few places one is able to spot (potentially) typed links, such
as "wikipedia":"de.wikipedia.org/wiki/Mexiko-Stadt", how-
ever, the relations between the resources is mainly established via literal values
one can look-up accross the offered APIs.
Google Maps
The Google Maps API is really a family of APIs providing geographic data for
maps applications. In the following we will focus on the Google Geocoding API19
that converts addresses into geographic coordinates and mainly deals with addresses
and geo-locations.
1. URI space design. Each resource of interest exposed via the API has its own URI
(for example, when looking up the address for a certain building20).
2. Representations. Both JSON and proprietary XML is served from respective
URIs (no content negotiation).
3. Hyperlinking. There is no indication for hyperlinking usage in the representations.
17
http://http://www.geonames.org/export/web-services.html.
18
http://http://ws.geonames.org/findNearbyPlaceName?lat=53.27&lng=-9.04.
19
http://http://code.google.com/apis/maps/documentation/geocoding/.
20
http://http://maps.googleapis.com/maps/api/geocode/json?address=IDA+Business+Park+Galway.
19 On Entities in the Web of Data 431
Netflix
Netflix is a company that offers DVD rental and on-demand video streaming. The
API deals with movies, actors, awards and the like. The Netflix OData API21 is a
representative example for Microsoft’s Open Data Protocol (OData) protocol,22 a
query and access protocol building upon Atom and AtomPub.
1. URI space design. The API exposes the main resources via distinct URIs, a
certain actor,23 for example.
2. Representations. Per default, the API serves Atom (Nottingham and Sayre 2005),
however also offers content negotiation. For example, curl -H "Accept:
application/json" http://odata.netflix.com/v1/Catalog/ yields the JSON
representation of the catalog.
3. Hyperlinking. The representations partially contain typed hyperlinks as specified
by the Atom standard, for example relating an actor to an award as in:
<link rel="..." href="People(189)/Awards" />. The relations
themselves24 are not dereferencable.
Twitter is a microblogging service allowing users to send and read other users’
messages (up to 140 characters) dealing mainly with said messages, people, and
geo-coordinates. The API25 comes in a REST flavour26 and in a so-called stream
version.
21
http://http://odata.netflix.com/v1/Catalog/.
22
http://http://www.odata.org/.
23
http://http://odata.netflix.com/v1/Catalog/People(189).
24
http://http://schemas.microsoft.com/ado/2007/08/dataservices/related/Awards.
25
http://http://dev.twitter.com/doc.
26
http://http://api.twitter.com/1/.
432 M. Hausenblas
1. URI space design. All main resources are exposed via URIs (such as a certain
user profile 27 ) organised in a flat space.
2. Representations. The XML and JSON representations dominate the API and
are served via dedicated URIs (/show.json?, for example), where for some
resources (like the public timeline) also RSS and Atom formats are provided.
3. Hyperlinking. Although one can find hyperlinks in the representations, there is
no evidence for utilising typed links to relate resources within the API.
Discussion
In terms of URI space design, the majority (88%) of the reviewed APIs do a great
job in exposing the respective main resources in a fine-granular manner. Very often
the URIs can considered to be hackable, which means a developer can easily follow
a pattern in constructing them. We note that for our discussion it is of no importance
if we consider the URIs opaque28 or not; in fact hackable URIs often lead to strong
coupling as the URI patterns are hard-coded for convenience reasons.
The outcome regarding the representations is somewhat inconclusive: some 77%
serve proprietary XML, only two support established standards such as Atom,
however most offer developer-friendly JSON (which seems to be sufficient for the
key-value structure of most responses).
Only a single API out of nine in fact supports true hyperlinking in its representa-
tions. Although the URIs for the resources have typically been made available (see
above), the majority of the APIs seem to ignore the potential benefits in referencing
them.
One of the most important – though often underrated – aspects of RESTful design is
how to name the things one wishes to talk about. In more technical terms one may
think of URI space design. Richardson and Ruby (2007) have documented valuable
good practices regarding the URI space design, but one can also obtain helpful hints
from the REST Wiki,29 where this topic is maintained under the “Noun” label.
Whereas RESTful design in general requires to identify those things we would
like to interact with, the following discussion operates under the presumption that
we want to establish a fine-grained access to data items in the Web of Data.
27
http://http://api.twitter.com/1/users/show.json?user id=817540.
28
http://http://rest.blueoxen.net/cgi-bin/wiki.pl?OpacityMythsDebunked.
29
http://http://rest.blueoxen.net/cgi-bin/wiki.pl?FrontPage#nid5TL.
19 On Entities in the Web of Data 433
Naming Things
Why is it essential to name things, that is, to assign URIs to all important resources
one exposes on the Web? Using a small motivation example may help shed some
light on this matter. Imagine a fictitious company that wants to inform about their
projects and how people are involved in it. One would expect to find, for example,
the following resources: people, projects, technologies, products and respective
URIs, such as:30
• For collection resources, such as all projects the company maintains, the URI
might be http://company.example.com/project
• Item resources, for example a particular project of the company, might be
identified by http://company.example.com/project/pr1 and a certain person by
http://company.example.com/people/roy.est.
Now, assuming one has the URI handy, one can use the URI in an application
(to obtain data from it) or link to the URI from another Web site. Obviously, if such
URIs are not available, one can not achieve the above things directly, and even more
seriously: the network effect is crippled.
Naming things one is dealing with on the Web, that is, minting URIs for all
main resources one exposes is essential for RESTful design. Non-observance
cripples the network effect.
A special sub-topic of URI space design worthy attention is how to deal with URI
fragments31 to identify sub-resources. Using URI fragments allows to link to things,
but they do not allow for interaction with said things through the uniform interface.
Concerning the URI fragment identifiers semantics, we need to consult the
Uniform Resource Identifier (URI): Generic Syntax (RFC3986) (Berners-Lee et al.
2005):
The semantics of a fragment identifier are defined by the set of representations that
might result from a retrieval action on the primary resource. The fragment’s format and
resolution is therefore dependent on the media type of a potentially retrieved representation,
30
Note that we use the terminology for the types of resources (collection and item resources)
suggested by Glenn Block in a recent blog post available via http://bit.ly/rest-resource-types.
31
http://http://www.w3.org/DesignIssues/Fragment.html.
434 M. Hausenblas
even though such a retrieval is only performed if the URI is dereferenced. If no such
representation exists, then the semantics of the fragment are considered unknown and are
effectively unconstrained. Fragment identifier semantics are independent of the URI scheme
and thus cannot be redefined by scheme specifications.
We note that most media types32 do not to specify URI fragments,33 and
where this is the case, the Architecture of the World Wide Web, Volume One
(AWWW) (Jacobs and Walsh 2004) gives us some guidance; cf. Sects. 3.2.1
(Representation types and fragment identifier semantics) and 3.2.2 (Fragment
identifiers and content negotiation) of the AWWW, especially concerning the
conflict resolution mechanism for content negotiation.
Summarising, URI fragments allow to identify sub-resources in a straight-forward
way. One should ensure that the fragments are made identifiable, for example in the
case of HTML this would require support by document authors.34
However, there is a number of unresolved issues around their usage, subject to
research – for example, concerning the interactions with these sub-resources35 – and
standardisation, for example regarding HTTP redirects.36
To understand entities in the context of the Web of Data, we will first discuss
how entities can be represented, following the AWWW (Jacobs and Walsh 2004).
Note that in the following, we will deliberately use the terms representation
(Fielding et al. 1999) and document synonymously; later on we will go into detail
regarding the notion of a document.
A fundamental characteristic of Web data is the ability to utilise “hyperlinks”,
essentially a URI reference between resources (Jacobs and Walsh 2004) that
typically comes with some link semantics attached. To assess the type and extent
of the supported link semantics concerning media types, we refer the reader to
Amundsen’s work on Hypermedia Types (Amundsen 2010).
When consuming Web data one typically has to deal with the extraction of
the data structure and its values from a representation. Furthermore, data values
might be provided as literal values or, through a hyperlink, as a reference to
another resource. In the following we will discuss these two options (literal-style
vs. reference-style) in greater detail; note, however, that this does not mean that
there can not or may not exist other design options at all.
32
http://http://www.iana.org/assignments/media-types/.
33
With a few exceptions, such as HTML and RDF/XML.
34
Essentially meaning that relevant elements in HTML need to be supplied with and id attribute.
35
http://http://oreillynet.com/xml/blog/2008/02/addressing fragments in rest 1.html.
36
http://http://lists.w3.org/Archives/Public/www-tag/2010Oct/0003.html.
19 On Entities in the Web of Data 435
<d i v >
<d i v>Name : M i c h a e l H a u s e n b l a s </ d i v>
<d i v>R e s i d e n c e : 32 B u s h y p a r k Lawn , Galway , I r l a n d </ d i v>
</ d i v>
<d i v >
<d i v>Name : M i c h a e l H a u s e n b l a s </ d i v>
<d i v>R e s i d e n c e : <a h r e f =” a d d r e s s . h t m l ”>my a d d r e s s </ a></ d i v>
< / d i v>
Providing data values via references allows for a greater flexibility compared
to literal values and enables the reuse of data within a site and across the Web.
However, it also comes with its costs: each reference needs to be resolved and the
referred document parsed, yielding additional costs in the data processing.
Consider the following two cases: Figs. 19.1 and 19.2 show an entity with
pure literal-style values, whereas Figs. 19.3 and 19.4 depict the case where partial
reference-style values are used.
436 M. Hausenblas
Literal-style vs. reference-style data values are design decision of the resource
owner, rather than characteristics of representations.
Entity Boundaries
The notion of a document has been the topic of recent discussions (cf. for exam-
ple Wilde 2009). In the following, we will explore if the notion of a document is
helpful in the context of the Web of Data and how this relates to entities.
To approach the issue of a “document notion”, let us first step back a bit and
discuss what are directly observable things on the Web. With directly observable we
mean that something can be measured, processed, stored, etc. in the widest sense.
In a first step we want to determine what directly observable things on the Web
are. As a starting point, we will use the Web’s Retrieval Algorithm as described
in Mendelsohn (2009): dereferencing a URI yields a representation of the resource
identified by the URI. We note that URIs and representations are directly observable
things, while resources are not directly observable. For example, a URI can be
bookmarked or the representation of a resource can be stored in a file. Resources, on
the other hand are purely conceptional and only are observable indirectly through
URIs and the resource representation at a given point in time.
Further, we acknowledge the fact that the hyperlink structure of the Web is crucial
for content discovery (Raman 2006). We note that although the discovery is enabled
by hyperlinks between resources, the actual communication necessarily needs to be
carried out using representations. In this context a special subset of resources is of
interest: information resource. We will use the definition of information resource as
of Jacobs and Walsh (2004), repeated here for convenience in Definition 1.
Definition 1. If all of the essential characteristics of a resource can be conveyed in
a message, the resource is an information resource.
For certain applications and use cases, the concept of an information resources
is essential, especially when dealing with metadata. Take for example the resource
“the current temperature in Galway, Ireland”. This resource is identified by the URI:
http://example.com/galway/temperature
19 On Entities in the Web of Data 437
<f o r e c a s t c i t y =” Galway”>
<t e m p e r a t u r e>15</ t e m p e r a t u r e >
</ f o r e c a s t >
@ p r e f i x m: <h t t p : / / p u r l . o r g / n s / meteo#> .
@ p r e f i x d : <h t t p : / / d b p e d i a . o r g / r e s o u r c e /> .
@ p r e f i x : <> .
d : Galway m: f o r e c a s t : t e m p F o r e c a s t .
: t e m p F o r e c a s t m: t e m p e r a t u r e : tempVal .
: tempVal m: c e l s i u s ” 1 5 ” .
Hyperlinking
Equipped with the reference-style design pattern and the idea of treating a resource
URI together with its representation as a unit for processing data, we are now ready
to approach the definition of an entity. While the term “entity” itself has already
438 M. Hausenblas
Fig. 19.7 Entity example from the Linked Open Data realm
been in use for a while (Bouquet et al. 2008; Umbrich et al. 2010), to the best of our
knowledge no agreed definition is available. We hence attempt to define an entity
in the following (cf. Definition 2), and note the usage of “connector” as of Fielding
and Taylor (2002).
Definition 2. An entity is a thematic view on resources across connectors, materi-
alised through hyperlinks.
The two important bits in Definition 2 are “across connectors” and “hyperlinks”;
the former acknowledging the fact that the actual data belonging to an entity is
potentially distributed over several data sources and the latter that, if the data items
are not explicitly connected, it is hard to impossible to construct an entity. One
can even go a step further and assert that entities as such make only sense when
the reference-style design is employed, as otherwise out-of-bound information is
necessary to consume related information in the Web. Note also that we propose
not to restrict what “thematic” might mean, as this is very likely depending on the
application that processes an entity.
Take, for example, Fig. 19.7: different Linked Open Data sources37 – homoge-
nous linked data as of Wilde (2010) – may expose different aspects, such as
price, technical features, carbon footprint, etc. regarding products through respective
resources. Assume now, one is interested to buy a certain laptop with a particular
price limit and carbon footprint. In this application, the entity of interest is “a
laptop”, and taking the interlinked data items from the four data sources together,
one is able to answer the query.
37
http://http://lod-cloud.net/.
19 On Entities in the Web of Data 439
While it seems that from the perspective of a consumer (who has to typically
deal with several data sources), the concept of an entity is pretty straight-forward,
in case of a data publisher it may not be so obvious. For the Web data publisher,
resources and resource identifiers are the primary design elements. Not only are
they (along with the choice of appropriate representations) the main building blocks,
but are typically considered sufficient in terms of organisation. Regarding the data
publisher side of Definition 2, with connector we mean in special a server, which
is assumed to be authoritative for a resource. However, one can also understand
the data publisher playing the role of a consumer regarding other data sources
(Volz et al. 2009).
The main limitation of the research presented in this paper lies in the fact that
it focuses on the read-only case (HTTP GET). A consistent and comprehensive
discussion of the “transactional view” is subject of future research, taking into
account if and how update, add, or remove would work without having a point of
reference, that is, a container, such as a document provides.
Further, we note that it has yet to be discussed how the concept of an entity
fits into proposed extensions of the REST style, such as Computational REST
(CREST) (Erenkrantz 2009), where computational exchange is the primary ex-
change mechanism between peers, hence relaxing the client-server distinction found
in REST.
Conclusion
Acknowledgments The author would like to thank Richard Cyganiak for the conversations
regarding the notion of document, Mike Amundsen for deeper insights into hypermedia linking
aspects, as well as Jonathan Rees and David Booth – in the context of the W3C task force
440 M. Hausenblas
“Architecture of the World Wide Semantic Web” – for ongoing discussions around HTTP
semantics. Last but not least, the author wants to express his gratitude to Erik Wilde for his
feedback and his continuing support to ensure that the chapter focuses on under-represented topics
in the REST research.
References
Introduction
Multimedia content have never been so widely disseminated as they are nowadays
and will exponentially be from now on. This is mainly due to the simplicity of tools
for the creation and dissemination of content and also to the accessibility of creative
people to those tools. The production of good content is not an exclusivity of large
production companies with expensive budgets anymore. Videos, music, photos,
and other media are achieving multi-million audience, reveling talent artists and
spreading messages that matter. However, the more content is represented as media
the more it becomes difficult to be indexed by search engines and organized by
applications. The drawback of this kind of content is its binary representation, whose
intrinsic semantics is unclear for computers. Search engines rely on surrounding
H. Mendonça ()
Laboratoire de Télécommunications et Télédétection – TELE, Université catholique
de Louvain, Louvain-la-Neuve, Belgium
e-mail: [email protected]
texts and few metadata to index media content, which works in most cases for search
purposes but it also leads to ambiguities, misunderstandings, obscurity, besides
limiting possible applications on the exploration of these data.
The identification of semantics in media content can still be done automatically
by computers. There is a considerable effort from the computer science and
electrical engineering communities on the recognition of patterns in images, videos,
audios and so on. They are achieving impressive results in terms of precision
and performance, but they are not scalable enough to describe large multimedia
repositories in a reasonable time or to be integrated to a webcrawler to index
media published on the web. Being more pragmatic, the description of media is
more precise and detailed when done manually by users because the content might
have different interpretations and might contain meanings that are not easily given
artificially. Besides that, pattern recognition still fulfills an important role in the
description of media due to its productivity in comparison to manual practice when
making short but effective descriptions.
We can see the need for media description not only on the Web, where there is no
content limitation, but also in specialized applications, where meanings are carefully
inherited from one or more domains of knowledge. These kinds of applications are
focused on purpose, such as video surveillance applications detecting unforeseen
situations, medical imaging applications detecting intra-corporeal elements using
radio and resonance, sport applications tracking players in the game to analyze
moves and improve performance, and many others that generate media with
meaningful content.
Once recognized, manually by human beings or automatically by computers,
media content and their meanings must be directly related and stored for posterior
use. In order to visualize a solution for the lack of media content’s representation, as
presented previously, we realized that: if media content and meanings are directly
related, then they can be provided together; if provided together, applications aware
of it would be able to stop relying on surrounding content and start making use of
semantic descriptions. Therefore, we have elaborated a few requirements to guide
the design of a solution for this purpose:
• Define a data model to represent meanings in media content: when meanings are
ready to be associated to the content, it is important to have a data model that
suits well their format and syntax, and also delimits the location where they are
present.
• Reuse what was recognized before: keep record of recognized meanings would
avoid repeating automated recognitions, saving computer resources and also
helping the analysis of massive data collected throughout time. Because media
content are immutable (they are not changed and if a change is needed a new
version is created), none of the records becomes outdated and can be permanently
reused for several purposes.
• Assist search engines on the indexation of media content: when storing media a
minimal content description is needed. Associating meanings to content helps
in the indexation process, since media can be found by textual search on all
20 A Resource Oriented Multimedia Description Framework 443
collected meanings. At the same time, existing search engines may be used
somehow as alternative ways to find content in addition to basic database
querying.
• Use open standards for representation, communication and publishing: to make
media and their meanings available for several computers, open standards should
be used in order to implement full interoperability. Therefore, information
stored may be represented in JSON1 or XML2 format, the Internet used as a
communication medium, and all stored content available on demand.
With these requirements in mind, we present through this chapter a proposal
to make multimedia description openly available, simplify the support for media
description for developers and apply the solution to the medical imaging domain,
which is relatively complex and relevant for the society. In “Multimedia Descrip-
tion” we describe segmentation and annotation, which are the data structure used to
describe media content. We illustrate the adoption of segments and annotations in
“Description of Medical Images” using a domain-specific application as an exam-
ple. Then we present in “The Yasmim Framework” a framework to help developers
adding support for multimedia description in existing and new applications. In the
sequence, we show in “Adapting an Application to Use the Framework” how an
existing application is adapted to support the framework. At last, we conclude
discussing benefits and issues of this approach in “Conclusion”.
Multimedia Description
A formal data model was created to support the description of multimedia files. This
data structure is based on segmentation and annotation techniques. Segmentation, or
fragmentation, consists of delimiting meaningful regions of media content (Shapiro
and Stockman 2001). This process determines whether the region is useful or not
for the purpose of the system application. This purpose guides the direct intervention
of the end-user when manually creating segments and the implementation of
recognition techniques to automatically delimit meaningful elements. Annotation
is the assignment of meanings to segments in order to describe their content.
When done manually by the user, a segment is selected and annotations are written
or dragged to it. When done automatically, segments are created by recognition
algorithms, indicating where the elements are located in the media, and annotated
according to what the algorithm was trained to recognize.
1
JavaScript Object Notation: http://www.json.org.
2
eXtensible Markup Language: http://www.w3.org/standards/xml/.
444 H. Mendonça et al.
Types of Segments
Spatial
The spatial segment delimits a static region in a visual media content. It can
be bidimensional or tridimensional. Bidimensional segments can be used for
images and video frames. Tridimensional segments can be used for 3D models.
Bidimensional segments contain a set of points involving a region of interest:
where x and y are coordinates of the points in the Cartesian plane of the content.
The value of x and y are correspondent to the pixels’ position of a bitmap media. In
a vectorial media, x and y are correspondent to the current canvas size, where the
number of pixels is dynamically defined by the graphical controller. The limits for
x and y are based on the image resolution and the pixels’ gradient. Tridimensional
segments contain a set of vertex:
where x, y and z are coordinates of the vertex. The value of x, y and z are
correspondent to the current canvas size, where the number of pixels is dynamically
defined by the graphical controller.
The use of spatial segments is more frequent in images, whether bidimensional
or tridimensional graphics, and less frequent in videos. The full content of an image
can be seen at once, while a video is usually composed of thousands or even millions
of frames, and its content is more meaningful when these frames are presented as a
sequence. Therefore, the segmentation of only one frame might be insignificant.
Temporal
where Ts is the starting timestamp and Te is the ending timestamp, both included.
The difference between Te and Ts is equal to the duration of the segment.
Spatio-Temporal
The spatio-temporal segment is a merge of the spatial and temporal segments’ con-
cepts. It associates a time tag for each one of an uninterrupted sequence of frames. In
an implementation level, it preserves all the characteristics of the spatial and tempo-
ral segments, but associates additional properties to the spatial segment, which are
a sequential number and a correspondent time instant. Because there is a possibility
of having two or more frames in the same timestamp, the sequential number was
introduced to keep the sequence of those frames, independent of their timestamp.
We can conclude that the formal definition of a spatio-temporal segment is:
Sst D ŒTs .fSs1 ; Ss2 ; :::; Ssn g/; Te .fSs1 ; Ss2 ; :::; Ssn g/ (20.4)
Segments by themselves are capable of meeting the needs to delimit several content
samples. It allows a precise attribution of meanings to the right location, using
annotations. However, there still exists gaps to fulfill in terms of representativeness.
These gaps are in the limbo between segments; and our approach to fulfill
them is creating links between segments. The arrangement of links has several
configurations, such as: sequence, hierarchy, composition, cause and effect, and
others. Seen as a sequence, links indicate that there is a logical order between the
segments, as hierarchy they indicate the refinement of a large segment in several
smaller ones, as composition they connect the parts of a bigger element, and as cause
and effect they indicate the impact that a segment may cause on other segments.
Types of Annotation
assigned to segments and links, covering from simple to complex media content.
The supported annotations are:
Property
Tagging
Transcription
Description
Description is a detailed text explaining the essence of the media content. It has the
same advantages and disadvantages of transcription, but with a different purpose.
Practical applications are story telling material, textual summarization, situation
description, scenario-based prototypes, etc.
AdHoc
the related media is already available for the user, appearing as an additional or
complementary information. This is due to the fact that AdHoc annotations are
informal, free-text, and can lead to erroneous decisions (Kompatsiaris and Hobson
2008).
Domain Concepts
several data sources and several clients. In theory, the middleware behind it can
be any application server available on the market that implements recent Java
Enterprise Edition (Java EE) Specification Requests (Java EE JSR).3 However,
we have tested it only with the Glassfish.4 It can manage instances of the same
application on spread machines, expanding the processing capability according to
users’ demands.
The application manages the information that come from clients and organizes
them in different databases. Each database was chosen according to the data that
they were designed to store. These databases are:
• Media File Repository: Media files are stored directly in the file/storage system.
The optimal efficiency on file access depends on the operating system and the
storage system in use. Files are located by name, which is not exactly the original
name, but the resource id registered in the database. To verify consistency, a batch
process checks periodically whether there is a database record for each stored file.
Orphan files are deleted in this process.
• Segmentation and Indexation Database: A relational database is used to store
references to files in the repository because of its robust indexation mechanisms.
It is also used to save segmentation data because tables have better support
to store and retrieve numbers, since segments are basically coordinates and/or
timestamps.
• Annotation Database: Annotations are stored in a document database system,
which processes text more efficiently than relational databases.
3
Java Community Process Java EE: http://jcp.org/en/jsr/platform?listBy=3&listByType=platform.
4
Glassfish Application Server: https://glassfish.dev.java.net/.
20 A Resource Oriented Multimedia Description Framework 449
The role of the client side is to process heavy operations, such as the support
for several modalities, automatic segmentation, automatic extraction of meanings,
and also to provide rich user interaction for intuitive manual segmentation and
annotation. The data is synchronized with the server, making the media and all
related data available for searching and sharing.
The server side provides REST web services (Fielding 2000), which is compat-
ible with several kinds of clients developed in different languages, platforms and
devices. According to REST architectural principles, the main data abstraction is
a resource, which is represented by a media resource in our architecture. Every
media and related information are reachable through unique identifiers, following
the principle of addressability. Identifiers are known as URI (Uniform Resource
Identifier),5 which is used by the HTTP protocol to locate resources on the web
(Richardson and Ruby 2007). With a REST-based framework, we could attach
segments and annotations to media, making slight modifications on the URI. This
way, not only search mechanisms can benefit from the media description, but many
other practical applications as well, since REST web services are easily accessible
by any socket library.
Figure 20.2 shows the server side where Yasmim runs. The application server
has two execution environments: The EJB Container and the Web Container. The
first one is appropriate to handle transactional data, which is suitable for operations
with the relational databases. The second one is appropriate to handle and generate
5
http://www.w3.org/TR/uri-clarification/.
450 H. Mendonça et al.
content based on the target users. This content is stored and retrieved by the EJB
Container and other sources and appropriately transformed for different purposes.
The EJB Container runs Yasmim’s business logic that takes care of the database
data. The Web Container runs Yasmim’s administration, which is the user interface
to perform back office (maintenance) operations, and the web services, which are
the interface with clients.
These containers have some facilities to access data. The JavaTM Persistence API 6
is a JavaTM specification for relational data access. It is capable of mapping table
with JavaTM classes in order to transform table tuples in JavaTM objects, consequently
simplifying data access. The Jersey RESTful API 7 is an implementation of the
JavaTM specification for providing and consuming REST web services. It is used
to implement and to consume REST web services. The Grizzly NIO API 8 is an
implementation of the New JavaTM IO specification. It is used to store, retrieve and
modify media files asynchronously, optimizing parallelism.
The platform is composed of the JavaTM Virtual Machine (JVM), MySQL
database, and CouchDB document database. They run on top of the operating
system, which is also responsible for the media storage. The JVM is responsible
for the execution of JavaTM programs, which includes the application server and
the applications running on it. MySQL9 is one of the fastest relational databases
available and its indexation, relational and transactional features are essential to deal
with a large amount of numbers and unique references, which should be consistent.
Finally, because annotations perform an important role in this research, they should
be stored in a high scalable way, such as the one provided by CouchDB,10 a
document based database (Anderson et al. 2010). All data in CouchDB is accessible
by REST web services, allowing clients to access it directly, without Yasmim
mediation, although only Yasmim can write data there.
Catalog of Services
The relevant services for general understanding are listed on Table 20.1. The first
column indicates the name of the service, helping the developer to identify which
service is more appropriate for his/her needs. Second column shows the HTTP
methods, that could be GET, POST, PUT, and DELETE. The third column shows the
relative URI, starting with “http://[server-name/domain]/resources”. The brackets
indicate that there is a value to fulfill. This value could be pre-defined, which is
the case of [type], or generated, which is the case of [id]. The last column lists the
6
JSR 317:http://jcp.org/en/jsr/summary?id=317.
7
JSR311:http://jcp.org/en/jsr/summary?id=311.
8
JSR51:http://jcp.org/en/jsr/detail?id=51.
9
http://www.mysql.com.
10
http://couchdb.apache.org.
20 A Resource Oriented Multimedia Description Framework 451
11
Universally Unique Identifier: http://www.ossp.org/pkg/lib/uuid/.
452 H. Mendonça et al.
Only media cannot be updated because media files are immutable. Segments
and annotations can be inserted, updated, queried and deleted normally. In case a
media file needs to be updated, a new version is created with the new file and the
previous version is kept historically. The implementation of filters on the server
would impact the overall performance. However, the decision to implement them
was made because they are atomic operations, which means that there is only one
algorithm for each filter and its output is exclusively used by the client. In order to
improve performance, we save a version of the filtered image to retrieve in case the
it is requested once again in the future, working as a buffer. The same rules are valid
for format. The saved versions have a different file name pattern. Besides the id, the
name also have a sequential number and the retrieval of the correct file is managed
by the framework.
The hypermedia aspect of the services helps to retrieve media resources ac-
cording to their respective mime types and also informs to application clients the
available filters for each requested kind of media. Yasmim does not offer other
references beyond these ones, thus hypermedia is not seen as a workflow but a set
of options available for retrieving and processing resources.
MedicalStudio
There are applications to help doctors on the analysis of such media content. The
one that we are taking into consideration is MedicalStudio because we have access
to the source code and the application needs a rich support for segmentation and
annotation of medical images. MedicalStudio is a component-oriented platform
designed to ease the creation of medical imaging workstations (Trevisan et al.
2007). Besides simplifying the work of developers, MedicalStudio also streamlines
clinical trials and end-user’s experience. The platform provides a collection of
reusable components that can be assembled to produce new applications considering
image processing, data access, interaction design and others. Each assembly of
components will produce a different application that may target different uses. In
the case of an image registration application, for example, each algorithm will be
seen as a component, and there will be several UI components to meet different user
20 A Resource Oriented Multimedia Description Framework 453
profiles: (a) a configuration UI for tuning algorithms used by engineers; (b) another
configuration UI for tuning options oriented for clinical researchers; and (c) a
visualization UI for doctors to perform their specific clinical diagnosis.
Figure 20.3 depicts MedicalStudio’s user interface, where an image of a mam-
mography is shown. Looking at the image, the doctor can visually identify
micro-calcifications, select them using spatial segments and annotate these segments
using domain-specific annotations, which is well known by the doctor, who is a
specialist in the field.
The platform is entirely written in CCC and relies on well accepted and powerful
libraries, such as Visualization Toolkit (VTK12 ) for visualization, Insight Segmen-
tation and Registration Toolkit (ITK13 ) for image segmentation and registration,
DCMTK14 for Digital Imaging and Communications in Medicine (DICOM15 )
interoperability and GTKmm16 for graphical user interface. These libraries are not
12
http://www.vtk.org.
13
http://www.itk.org.
14
http://dicom.offis.de/dcmtk.php.en.
15
http://dicom.offis.de.
16
http://www.gtkmm.org.
454 H. Mendonça et al.
always enough in specific cases, so that list is not fixed and the architecture is
flexible enough to allow interoperability with any other toolkit as far as it can be
bound with CCC.
17
Protégé ontologies modeling platform: http://protege.stanford.edu.
20 A Resource Oriented Multimedia Description Framework 455
In order to access this and other services, the library LibcURL,18 a client-side
URL transfer library, was added to MedicalStudio allowing HTTP connections to
the server.
The current MedicalStudio version implements only one kind of segmentation,
the spatial one, and three kinds of annotations, which are:
1. Property: used to annotate low level features of the image.
2. Description: if necessary, some description of the segment can be added.
3. Domain concept: the most common annotation, since MedicalStudio implements
an ontology, as described in “Breast Diagnosis Domain Representation”.
The process of mammography screening is as follow:
1. Visualization: mammographies are analyzed, they are retrieved with the patient
records from the PACS19 and HIS20 ;
2. Lesion detection: each visible lesion in the image is detected, spatially localized
(manually or with automatic algorithm) and categorized in one of the 5 possible
type of lesions;
3. Lesion annotation: for each lesion a set of standardized characteristics is entered,
all theses characteristics are dependants on the type of the lesion, the whole set
is organized in an ontology based on a medical standard called BIRADS;
4. Automatic annotation: alongside the manual user annotation, a set of automatic
algorithms characterises the same lesion with low level descriptions;
5. Reporting: finally, a diagnosis report is generated from the whole set of annota-
tions made on all images and sent to the hospital information system.
Analyzing that process, we can exposes the inputs and outputs and maps them to
YASMIM services in the integrated architecture. Table 20.2 lists them all. For each
input and output there is a related web service, in the second column, and the type
of data that has been manipulated, in the third column.
Integrated with Yasmim, MedicalStudio has another immediate benefit, which
is the possibility to support multiple domains. It would allow specialists from
different medical specialties to analyze the same image, enabling multi-disciplinary
diagnosis. It would also allow the annotation of other kinds of images, besides
mammographies. And last but not least, all data and annotations will be accessible
to other medical clients, that is a simple and standardized way in addition to the
complex DICOM document format. That access will allow the development of very
thin clients, such as web clients or even smart-phone and tablet clients.
18
http://curl.haxx.se/libcurl/.
19
PACS : Picture Archiving and Communication System, usually implemented with the DICOM
standard. http://medical.nema.org.
20
HIS : Hospital Information System, a “in-house” system, but HL7 standard starts spreading.
http://www.hl7.org.
20 A Resource Oriented Multimedia Description Framework 457
Conclusion
References
Anderson, C., Lehnardt, J., Slater, N.: CouchDB: The Definitive Guide. O’Reilly Media Inc.,
Sebastopol, CA, USA (2010)
D’Orsi C.J., Bassett L.W., Berg W.A.: Breast Imaging Reporting and Data System: ACR BI-
RADS-Mammography (ed 4), Reston, VA, American College of Radiology (2003)
Fielding, R.: Architectural styles and the design of network-based software architectures. Ph.D.
thesis, University of California, Irvine (2000)
Gruber, T.R.: A translation approach to portable ontology specifications. Knowledge Acquisition
5, 199–220 (1993)
Kompatsiaris, Y., Hobson, P.: Introduction to semantic multimedia. In: Semantic Web Services:
Concepts, Technologies, and Applications, chap. 1, pp. 3–13 (2008)
Richardson, L., Ruby, S.: RESTful Web Services. O’Reilly Media Inc., Sebastopol, CA, USA
(2007)
Shapiro, L.G., Stockman, G.C.: Computer vision. Prentice Hall. (2001)
Trevisan, D., Nicolas, V., Macq, B., Nedel, L.: Medicalstudio: A medical component-based
framework. In: Workshop de Informatica Medica - WIM (2007)
Tudorache, T., Noy, N.F., Tu, S.W., Musen, M.A.: Supporting collaborative ontology development
in Protégé. In: Seventh International Semantic Web Conference, Karlsruhe, Germany, Springer.
(2008)
21
http://www.apache.org/licenses/LICENSE-2.0.html.
22
http://mediatic.multitel.be/platforms/3dmedia.html.
Chapter 21
Metadata Architecture in RESTful Design
Abstract Metadata is a key component of the REST architecture that can be used to
provide additional information about web resources. The ultimate goal of metadata
is to transform web resources into self describing information units that can be
automatically processed by software agents. We review the main options present in
the HTTP standard to provide metadata for web resources. We also review the main
mechanisms proposed by standard organizations like the W3C and the IETF as well
as by groups of practitioners to provide additional ways of associating metadata to
resources. The connection between metadata and semantic web technologies is also
explored. Finally the notion of resource and metadata discovery is also introduced
and the main discovery technologies are reviewed.
Introduction
Metadata is one of the data elements in the REST web architectural style along
with resources, resource identifiers, representations and control data (Fielding and
Taylor 2000). In this context, metadata can be defined as “machine understandable
information about web resources” (Berners-Lee 1998). This brief definition remarks
the importance of metadata as the element of RESTful design enabling automatic
processing of web resources. This aspect is often overlooked in the design of
RESTful web services where the role of metadata is many times restricted to
provide information about the syntax used in the resource representation. This
“representation metadata” encoded as a media data type in a HTTP header is
exchanged between HTTP parties in the content negotiation process in order to
select a suitable representation for a certain web resource.
The HTTP protocol makes metadata a first class object in the protocol specification.
The main place to store metadata in HTTP messages is the collection of HTTP
headers sent in every HTTP request and response.
Entity headers can be classified in different categories. Some headers contain
meta information about the representation of the requested resource being trans-
ferred in the entity body of the HTTP response. The most important representation
HTTP header is the “Content-Type” response header that specifies the media
type for the representation. A different kind of entity headers expose meta data
about the resource rather than the representation being transferred. For example
the “Allow” HTTP header contains the list of HTTP methods supported by the
resource. Finally, control data headers contain information necessary for the correct
interaction between client and server. This information is not directly related to the
representation of the resource. The Cache-Control header is an example of this kind
of headers.
The main mean to provide the semantics of the resource representation retrieved
by the client is the media type returned in the “Content-Type” HTTP header. This
21 Metadata Architecture in RESTful Design 461
of web resources. Media types just provide HTTP agents with a reference to the
semantics of the representation but it does not support a mechanism for describing
these semantics. HTTP agents must have support in advance for the media type
of the resource representation since it is impossible for agents to acquire support
for an unknown type just from the media type declaration present in the HTTP
“Content” header.
An additional problem is the rigidity of the media type standard to provide
custom semantics for a specific resource. Private custom media type headers can be
used for particular applications but their semantics cannot be automatically retrieved
and processed by third party HTTP agents.
Different solutions to provide the semantics of the resource representation have
been proposed. IETF RFC2068 (Fielding et al. 1997) of the HTTP protocol,
superseded by IETF RFC2616, proposed the inclusion of a “Link” header (Conolly
1999) that could be used to link an associated resource to the resource representation
being retrieved. This header has been used by different metadata retrieval proposals
to associate metadata with a web resource. The use of an additional HTTP header
has the advantage of not requiring the HTTP agent to retrieve the whole document in
order to check and process the associated metadata. This can be accomplished with
a single HEAD HTTP request that will retrieve the headers of the HTTP message.
One major drawback of using the HTTP HEAD method is that it is not widely
supported by server and client implementations of the HTTP protocol.
Using fixed, well known URIs where information about web resources in
a domain could be retrieved, as proposed in IETF RFC5785 (Nottingham and
Hammer-Lahav 2010), is another possible alternative for the association of metadata
to resources that is being used in different metadata mechanisms.
WEBDAV extensions to the HTTP protocol introduced a different approach to
the retrieval of metadata for a resource using an additional HTTP verb “PROPFIND”
that make WEBDAV (Goland et al. 1999) enabled servers return all the metadata
information associated with a resource.
Nevertheless, none of these mechanisms offers a solution for all the possible
use cases involving the retrieval of metadata. In these cases, the common approach
is to embed metadata in the resource representation or link the metadata from the
representation if the resource representation supports hyperlinking. This approach
can be problematic because HTTP agents must retrieve the full representation and
process it to retrieve the metadata.
in the document, a generic HTML container block like “div” or “span” can be used
and the semantics of the information could then be added as the value of standard
HTML attributes.
The Microformats proposal ultimate goal is to define standard ways of structuring
HTML tag elements and property vocabularies in order to describe semantic
information so it can be easily reused by humans in the design process of HTML
documents and by software agents automatically processing web resources.
The main characteristics of the microformats initiative can be summarized as
follows:
• Use of HTML structure plus a plain vocabulary to define semantics
• Community driven
• Embeddable in HTML, XHTML, Atom, RSS, and XML documents
• Focus on simplicity, reuse and minimalism
Currently, there is a list of ten microformats considered to be stable, including
hCalendar for expressing calendar events, hCard used to represent people and
organizations, or rel-license to state content licenses in a document.
The following example shows sample HTML code including hCalendar mi-
croformat markdown. The “event”, “summary”, “dtstart” and “location” property
values are part of a controlled vocabulary used by the microformat to add semantic
information to the data contained into standard span HTML tags. The structure of
the HTML tags containing the vocabulary values in the class HTML properties is
also prescribed by the hCalendar specification.
<span class="vevent">
<span class="summary">The microformats.org site
was launched</span>
on <span class="dtstart">2005-06-20</span>
at the Supernova Conference
in <span class="location">San Francisco, CA, USA</span>.
</span>
problem since XML namespaces could be used to prevent name collisions among
metadata identifiers but present important difficulties for their integration into plain
HTML documents.
Another problem with the microformats is extensibility. It is impossible to add
a custom microformat to a HTML document. The only description mechanism
available for metadata is XMDPP and at the present moment is more suitable
for documenting microformats for humans than for description of arbitrary mi-
croformats that could be automatically parsed by agents. Besides, the lack of
unique identifiers for properties makes difficult to reuse properties between different
microformats.
<span typeof="cal:Vevent">
<span property="cal:summary">The microformats.org site
was launched</span>
on <span property="cal:dtstart" content="20050620">
2005-06-20</span>
at the Supernova Conference in
<span property="cal:location">San Francisco, CA, USA</span>.
</span>
to extract the actual metadata from the representation. These metadata can link to
additional metadata, for example, a document containing the OWL description of
the class and properties used to annotate the representation.
Gleaning Resource Description from Dialect of Languages (GRDDL) (Connolly
2007) is a W3C recommendation describing an alternative mechanism to add
metadata to web resources. The starting point of GRDDL is the existence of a
variety of possible representations for web resources. Many of them are XML based:
plain XHTML documents, Atom feeds, etc. In many occasions, modifying these
representations to embed semantic metadata using microformats or RDFa is not
possible. One possibility to add semantic metadata to the resource is to provide
an additional representation for the resource containing only the metadata for the
resource being exposed, for example, a RDF document, that can be retrieved by
HTTP agents using HTTP content negotiation. This approach has the drawback of
creating and maintaining the additional representation.
Resource authors using GRDDL link an algorithmic transformation capable of
generating a faithful rendition of the XML representation in RDF, instead of directly
linking the metadata of the resource. GRDDL recommended way of describing
transformations is using XSL Transformations (XSLT).
Linking GRDDL transformations from XML based resource representations
can be accomplished just adding the GRDDL namespace declaration to
the document and adding a “grddl:transformation” property pointing at the
transformation. Transformations for whole XML dialects can be linked using
the “grddl:namespaceTransformation” property. XHTML documents can be used
with GRDDL adding the GRDDL namespace as a metadata profile and linking the
transformation using a link tag with a “transformation” value for the “rel” attribute.
One of the main use cases for GRDDL is to transform XHTML documents
annotated using microformats into RDF representations using some equivalent
vocabulary. The following example shows a variant of the hCal microformat
example considered before. In this example, a GRDDL transformation renders the
same RDF graph that was embedded in the RDFa annotated version.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head profile="http://www.w3.org/2003/g/data-view">
<link rel="transformation"
href="http://www.w3.org/2002/12/cal/glean-hcal"/>
</head>
<body>
<span class="vevent">
<span class="summary">The microformats.org site
was launched</span>
on <span class="dtstart">2005-06-20</span>
at the Supernova Conference
in <span class="location">San Francisco, CA, USA</span>.
</span>
</body>
</html>
468 A. Garrote Hernández and M.N. Moreno Garcı́a
GRDDL offers also a good opportunity for reusability. The GRDDL community
has collected transformations for many existing microformats as well as for other
non HTML based dialects e.g. the Atom format that can be directly linked by authors
of these representations. GRDDL can be used by Microformats publishers as an easy
way to provide an alternative representation for the metadata of a resource that can
be used by agents working with W3C semantic technologies.
Services discovery can be described as the process allowing two automated agents
to start some kind of useful interaction. In the process both parties discover which
kind of services are offered by the other. In the context of web resources, we can
talk about two kind of discovery process: service discovery and descriptor discovery
(Hammer-Lahav 2010). Service discovery deals with agents looking for services
with a certain capability. Descriptor discovery involves a software agent trying
to discover the capabilities supported by a resource. The availability of metadata
is one of the services that can be detected in the service discovery mechanism,
metadata themselves can also be used to make possible the discovery of other kind
of capabilities as well as enabling service discovery.
In previous sections, different ways of adding metadata to a resource have
been examined. Previously reviewed mechanisms like the embedding of metadata
into resource representations using microformats and RDFa or linking a GRDDL
transformation capable of generating metadata from a representation, present the
problem of not being automatically discoverable by HTTP agents. Agents must
obtain the full representation of the HTTP resource and process it in order to detect
the presence of metadata description mechanisms.
Metadata discovery protocols and specifications try to solve these limitations
providing two features:
• Standard protocols for the automatic retrieval of resource’s metadata.
• Shared vocabularies for the description of resource services.
Discovery mechanisms must have certain desirable features that are also common
to any other metadata mechanisms (Umbrich et al. 2009):
• Self declarative: the resource must be capable of linking the resource description.
• Direct accessible: the resource description must be retrievable without requesting
the resource being described.
• Compliant with web architecture.
• Scale to web size.
• Extensible: the description mechanism must allow authors of resource descrip-
tors to add arbitrary metadata in the description.
• Granular: a resource descriptor can be used to describe a single resource or a set
of resources.
21 Metadata Architecture in RESTful Design 469
Conclusions
The current state of the metadata architecture in the design of RESTful web services
is still a work in progress.
As RESTful APIs are becoming more and more usual and a higher degree of
automation and interconnection is required, the necessity of a standard metadata
layer is becoming more evident. In this chapter we have reviewed some of the main
technologies trying to address the architectural issues introduced by the integration
of semantic metadata in the HTTP protocol.
470 A. Garrote Hernández and M.N. Moreno Garcı́a
Four main techniques have been introduced to associate metadata with resource
representations:
• Providing metadata as an alternative representation for the resource that can be
retrieved using content negotiation.
• Embedding metadata within the resource representation.
• Linking metadata annotations from the resource representation.
• Linking metadata annotations from the headers of the HTTP message or a well
known URI location.
Microformats have been used as a simple mechanism to embed metadata in
HTML documents. Microformats is the most extended technology to add explicit
semantics to HTML representations but this technology is lacking in extensibility
and presents a serious drawback due to the use of a flat namespace to describe
properties instead of standard XML namespaces and URIs. To solve these problems,
RDFa presents an alternative mechanism to embed metadata in XHTML documents
in a compliant way with W3C standards for the semantic web. RDFa allows
publishers of web resources to add the full potential of semantic web technologies
to their service APIs, like the ontology description language OWL and standard
vocabularies like FOAF at the same time that it preserves the simplicity and low
entry barrier of the Microformats proposal.
A bridge between both semantic annotation mechanisms can be found in
the GRDDL W3C recommendation. GRDDL provides the means for linking an
algorithmic transformation to a resource representation that will render as a result
of its application, the equivalent RDF triples graph. GRDDL transformations can be
reused by resource publishers and a whole collection of GRDDL transformations
for many microformats is already available. GRDDL makes possible the integration
of annotation mechanisms, metadata vocabularies and description mechanisms.
Metadata discovery is another open problem in order for autonomous HTTP
agents to be able to identify the available metadata in the services exposed by
API providers. Automatic discovery of these metadata will open new ways of
interaction between agent and servers. The POWDER W3C recommendation and
the XRD/LLDR protocol stack try to offer solutions to this problem, specifying
linking mechanisms that do not require the HTTP client to retrieve and process the
full representation of the resource. Metadata can be linked to the HTTP message
using the Link HTTP header that can be retrieved using the HEAD HTTP method
without downloading the HTTP message body or can be placed into well defined
standard URIs that can be queried by clients, for example, in the “.well-known/host-
meta” path. They also define standard ways of adding arbitrary metadata to services
and the mechanism for its retrieval.
Metadata is already making possible the automatic interaction between HTTP
agents in web protocols like the OAuth authentication mechanism. In the nearly
future, better metadata support in RESTful APIs will make possible to automate new
kind of interactions offering important benefits to users. The emergent properties as
well as the interoperability capacities offered by semantic metadata will also make
possible to build more robust HTTP agents and use these APIs in new ways not
anticipated by their original designers.
21 Metadata Architecture in RESTful Design 471
References
B. Adida, M. Birbeck, and S. Pemberton. HTMLCRDFa 1.1, support for rdfa in html4 and html5.
W3C working draft, W3C, October 2010. http://www.w3.org/TR/rdfa-in-html/.
S. Allamaraju. RESTful Web Services Cookbook. O’Reilly, February 2010.
D. Beckett. RDF/xml syntax specification (revised). W3C recommendation, W3C, February 2004.
http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/.
T. Berners-Lee. Design issues of web architecture. 1998.
D. Connolly. Gleaning resource descriptions from dialects of languages (GRDDL). W3C recom-
mendation, W3C, September 2007. http://www.w3.org/TR/2007/REC-grddl-20070911/.
H. Conolly. An Entity Header for Linked Resources, October 1999.
R. T. Fielding. Architectural Styles and the Design of Network-based Software Architectures. PhD
thesis, University of California, Irvine, Irvine, California, 2000.
R. Fielding, J. Gettys, J. Mogul, H. Frystyk, and T. Berners-Lee. Hypertext Transfer Protocol –
HTTP/1.1. RFC 2068 (Proposed Standard), January 1997. Obsoleted by RFC 2616.
R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and T. Berners-Lee. Hypertext
Transfer Protocol – HTTP/1.1. RFC 2616 (Draft Standard), June 1999. Updated by RFCs 2817,
5785.
R. T. Fielding and R. N. Taylor. Principled design of the modern web architecture. In ICSE ’00:
Proceedings of the 22nd international conference on Software engineering, pages 407–416,
New York, NY, USA, 2000. ACM.
Y. Goland, E. Whitehead, A. Faizi, S. Carter, and D. Jensen. HTTP Extensions for Distributed
Authoring – WEBDAV. RFC 2518 (Proposed Standard), February 1999. Obsoleted by RFC
4918.
E. Hammer-Lahav. LRDD: Link-based Resource Descriptor Discovery, Draft rev 6. Internet Draft,
May 2010.
E. Miller and F. Manola. RDF primer. W3C recommendation, W3C, February 2004.
http://www.w3.org/TR/2004/REC-rdf-primer-20040210/.
M. Nottingham and E. Hammer-Lahav. Defining Well-Known Uniform Resource Identifiers
(URIs). RFC 5785 (Proposed Standard), April 2010.
S. Pemberton, B. Adida, S. McCarron, and M. Birbeck. RDFa in XHTML: Syntax and processing.
W3C recommendation, W3C, October 2008. http://www.w3.org/TR/2008/REC-rdfa-syntax-
20081014.
J. Umbrich, M. Hausenblas, E. Hammer-Lahav, and E. Wilde. Discovering resources on the web.
DERI technical report, DERI, August 2009.
Chapter 22
RESTful Services with Lightweight
Machine-readable Descriptions
and Semantic Annotations
– Jim Hendler
Abstract REST was originally developed as the architectural foundation for the
human-oriented Web, but it has turned out to be a useful architectural style
for machine-to-machine distributed systems as well. The most prominent wave
of machine-oriented RESTful systems are Web APIs (also known as RESTful
services), provided by Web sites such as Facebook, Flickr, and Amazon to facilitate
access to the services from programmatic clients, including other Web sites.
Currently, Web APIs do not commonly provide machine-processable service
descriptions which would help tool support and even some degree of automation
on the client side. This chapter presents current research on lightweight service
description for Web APIs, building on the HTML documentation that accompanies
the APIs. descriptions. HTML documentation can be annotated with a microformat
that captures a minimal machine-oriented service model, or with RDFa using the
RDF representation of the same service model. Machine-oriented descriptions (now
embedded in the HTML documentation of Web APIs) can also capture the semantics
of Web APIs and thus support further automation for clients. The chapter includes
a discussion of various types and degrees of tool support and automation possible
using the lightweight service descriptions.
Introduction
This book deals extensively with RESTful services and Web APIs,1 a machine-
oriented part of the Web. In contrast to other technologies focused on services or
distributed computing, RESTful services seldom come with machine-processable
1
In this chapter, we use the terms such as “Web API”, “RESTful service” etc. interchangeably.
J. Kopecký ()
Knowledge Media Institute, Open University, Walton Hall, Milton Keynes, MK7 6AA, UK
e-mail: [email protected]
service descriptions that would enable client-side tool support and even some degree
of automation.
The reasons for the reluctance of Web API providers to create and maintain
machine-processable service descriptions likely stem from the DRY principle
(Don’t Repeat Yourself ): on one level, service providers already produce HTML
documentation for their services and they do not want to maintain another de-
scription; and on another level, RESTful systems (are supposed to) use “hypertext
as the engine of the application state” – the clients should be guided by the
hypertext structure of the resources of a given service, rather than by some external
service descriptions. Moreover, there are currently no widely-accepted standards for
machine-processable descriptions of RESTful services, increasing the uncertainty
about adopting heavyweight technologies such as WADL because the effort might
be wasted if another technology becomes the standard.
In this chapter, we show a lightweight approach to describing RESTful services
in a machine-processable form. The approach builds on a minimal service model
that covers the important aspects of the structure of Web services. We show two
simple ways to structure the existing HTML service documentation – a microformat
called hRESTS and a generic standard form called RDFa – to provide machine-
processable service descriptions with no duplication of content.
On top of machine-readable service descriptions, we demonstrate a straight-
forward application of Semantic Web Services approaches for further advanced
machine processing and automation. In particular, we capture service semantics
using the W3C standard SAWSDL (Semantic Annotations for WSDL and XML
Schema 2007) and the W3C-acknowledged research proposal WSMO-Lite (Fensel
et al. 2010), in the spirit of earlier works called WSDL-S (Akkiraju et al. 2005) and
SA-REST (Sheth et al. 2007).
The aim of employing semantic technologies is to help with the following tasks:
discovery matches known Web services against a user goal and returns the services
that can satisfy that goal; ranking orders the discovered services based on user
requirements and preferences so the best service can be selected; composition
puts together multiple services when no single service can fulfill the whole goal;
invocation then communicates with a particular service to execute its functionality;
and mediation resolves any arising heterogeneities.
Our research, whose results are presented in this chapter, is driven by the
following conclusions drawn from previous works on service description and from
the progress towards the Web of Data:
• Semantics are essential to reach a minimum level of automation during the life-
cycle of services;
• Any solution to publishing services that aspires to be widely adopted should build
upon the various approaches and standards used on the Web, e.g. RDF, SPARQL
and Web APIs;
• Linked Data principles are important for publishing large amounts of semantic
data, both for human and machine consumption;
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 475
In their structure and behavior, RESTful services can be very much like common
Web sites (Richardson and Ruby 2007). From the Architecture of the Web (Archi-
tecture of the World Wide Web 2004) and from the REST architectural style, we can
extract the following concepts inherent in RESTful services:
• A resource, identified by a URI which also serves as the endpoint address where
clients can send requests.
• Every resource has a number of methods (in HTTP, the most-used methods are
GET, POST, PUT and DELETE) that are invoked by means of request/response
message exchanges.
• The messages can carry hyperlinks, which point to other resources and which the
client can navigate when using the service.
• A hyperlink can simply be a URI, or it can be a form which specifies not only the
URI of the target resource, but also the method to be invoked and the structure of
the input data.
Note that even though we talk about RESTful services, the architecture of the
Web contains no formal concept of a service as such. On the Web, a service
is a group of resources; such grouping is useful for developing, advertising and
managing related resources.
While the resources of the service form a hypermedia graph, the interaction of
a client with a RESTful service is a series of operations where the client sends
a request to a resource and receives a response that may link to further useful
476 J. Kopecký et al.
similar
payment resources
processing
confirmation
my bookings
hyperlink
or form
resources. The hypermedia graph (the links between resources) guides the sequence
of operation invocations, but the meaning of a resource is independent of where it is
linked from; the same link or form, wherever it is placed, leads to the same action.
Therefore, the operations of a RESTful service can be considered independently
from the graph structure of the hypertext.
In this chapter, we build upon the independence of operations and hypertext.
To illustrate this independence, and to show how a programmatic client interacts
with a service effectively by invoking a set of operations, treating the hypertext
links as data, the subsections below describe an idealized hypertext hotel reservation
service with a RESTful API. Section “Example Hotel Booking Service, Viewed
as Hypertext” (page 476) describes the service as a hypertext graph of resources,
“Turning Hypertext into Operations” (page 478) turns to view the service as a set
of operations, and then in “HTML Description of the Example Service” (page 479),
we discuss how such a RESTful API would typically be documented in HTML.
API documentation is the basis for our lightweight service descriptions, as detailed
further in this chapter.
Figure 22.1 illustrates an example RESTful hotel booking service, with its resources
and the links among them. Together, all these resources form the hotel booking
service; however, the involved Web technologies actually work on the level of
resources, so service is a virtual term here and the figure shows it as a dashed box.
The “service description” (page 479) is a resource with a stable address and
information about the other resources that make up the service. It serves as the
initial entry point for client interaction. In a human-oriented Web application, this
would be the homepage, such as http://hotels.example.com/.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 477
−17
service Sep 11 2 rates Rome hotel 1 details
Rome, available (still has rooms in Sep)
description
Rome, May 1−4 1 rate Rome hotel 2 details
form
with New Y available (available also in May)
ork, Au
input g 3−5
fields 1 rate
NY hotel 1 details
available
payment
processing
Fig. 22.2 Detail of example hotel reservation service resources for hotel search and hotel details
The existence of such a stable entry point lowers the coupling between the
service and its clients, and it enables the evolution of the service, such as adding
or removing functionality. A client need only rely on the existence of the fixed entry
point, and it can discover all other functionality as it navigates the hypermedia.
(However, in many cases, a programmatic client is programmed against a given
service description before it uses the service, making it harder to react dynamically
to changes of the service. This is especially true in service-description-driven
technologies such as most of tools for WS– Web services, but it is also common
with access libraries for Web APIs, such as the many “API kits”2 for the Flickr API.)
The service description resource of our example service contains a form for
searching for available hotels, given the number of guests, the start and end dates and
the location. The search form serves as a parametrized hyperlink to search results
resources that list the available rates, as detailed in Fig. 22.2; one resource per every
unique combination of the input data. The form prescribes how to create a URI that
contains the input data; the URI then identifies a resource that returns the list of
available hotels and rates for the particular inputs. As there is a large number of
possible search queries, there is also a large number of results resources, and the
client does not need to know that all these resources are likely handled by a single
software component on the server.
The search results are modeled as separate resources (as opposed to, for instance,
a single data-handling resource that takes the inputs in a request message of a
POST method), because it simplifies the reuse of the hotel search functionality in
other services or in mashups (lightweight compositions of Web applications), and it
also supports caching of the results. Creating the URIs for individual search results
resources and retrieving the results (with HTTP GET) is easier in most programming
frameworks than POSTing the input data in a structured data format to a single Web
resource that would then reply with the list of available hotels and rates.
2
See http://www.flickr.com/services/api/#kits.
478 J. Kopecký et al.
Search results are presented as a list of concrete rates available at the hotels in
the given location, for the given dates and the number of guests, as also shown
in Fig. 22.2. Each item of the list contains a link to further information about the
hotel (e.g. the precise location, star rating, guest reviews and other descriptions),
and a form for booking the rate, which may take as input the payment details (such
as credit card information) and an identification of the guest(s) who will stay in
the room. The booking data is submitted (POSTed) to a payment resource, which
processes the booking and redirects the client to a confirmation resource, as shown
in Fig. 22.1. The content of the confirmation can serve as a receipt.
The service description resource also contains a link to “my bookings”, a re-
source that lists the bookings of the current user (this would require authentication).
This resource links to the confirmations of the bookings done by the user. With such
a resource available to them, client applications do not need to have a local store for
the information about performed bookings.
The confirmation resources may further provide a way of canceling the reser-
vation (not shown in the pictures, could be implemented with the HTTP DELETE
method).
So far, our description of the example hotel reservation service has focused on the
hypermedia aspect: we described the resources and how they link to each other.
Alternatively, we can also view the service as a set of operations available to the
clients – as an API.
The resources of the service (the nouns) form a hypermedia graph (shown in
Fig. 22.1). The interaction of a client with a RESTful service is a series of operations
(the verbs or actions) where the client sends a request to a resource and receives a
response that may link to further useful resources. Importantly, the links need not be
only simple URIs, but they can also be input forms that indicate the URI, the HTTP
method, and the input data.
The graph nature of a hypermedia service guides the sequence of operation
invocations, but the meaning of a resource is independent of where it is linked from;
the same link or form, wherever it is placed, always means the same operation.
Therefore, the operations of a RESTful service can be considered independently
from the graph structure of the hypertext.
In Fig. 22.3, we extract the operations present in our example service. The search
form in the service description (homepage) represents a search operation, the hotel
information pages linked from the search results can be viewed as an operation
for retrieving hotel details, the reservation form for any particular available rate
becomes a reservation operation, and so on.
An operation-oriented view on RESTful services brings them closer to common
programming environments; it is a natural view for programmers of specialized
client applications.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 479
search(date, city)
Hotel booking service hotel list of rates (and hotels)
available information
service rates list getHotelDetails(hotel)
description detailed info about hotel
Web APIs, or indeed services of any kind, need to be described in some way, so
that potential clients can know how to interact with them. While Web applications
are self-describing to their human users, Web services are designed for machine
consumption, and someone has to tell the machine how to consume any particular
service.
Public RESTful services are universally described in human-oriented docu-
mentation (for instance, see Flickr API3 and Amazon Simple DB4 ) using the
general-purpose Web hypertext language HTML. Typically, such documentation
will list the available operations (calling them API calls, methods, commands etc.),
their URIs and parameters, the expected output and error conditions and so on; it is,
after all, intended as the documentation of a programmatic interface.
The following might be an excerpt of a typical operation description for our
example hotel reservation service:
ACME Hotels service API
getHotelDetails
Invoked using the method GET at http://example.com/h/id
id - the identifier of the particular hotel
hotel details in an ex:hotelInformation document
3
http://flickr.com/services/api.
4
http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide.
480 J. Kopecký et al.
In the hypertext of the example service, the service has five operations but only
two are directly accessible from the service description resource. All five operations
can be described in a single HTML document, but the client would not know
any concrete hotel identifiers to invoke getHotelDetails() before it does its
first hotel search; similarly, the client won’t have any confirmation ID to invoke
getCofirmationDetails() before it makes its first reservation. While using
the service, the client may save hotel or confirmation identifiers and use them later
to invoke these operations without going through availability searches or the list of
“my bookings”; this behavior is roughly equivalent to how bookmarks work in a
Web browser.
5
URI templates are defined for instance in WSDL 2.0 HTTP Binding (Web Services Description
Language (WSDL) Version 2.0: Adjuncts 2007) in Sect. 6.8.1.1.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 481
Table 22.1 Mapping RESTful services into a minimal service model, using WSDL terminology
RESTful services Minimal service model
Service (a group of resources) Service
Resource – (mapped below, in conjunction with methods)
HTTP method on a resource Operation (specifying a method and a resource
address)
Method request/response Operation input/output message
Resource representations – (treated as message data)
Hyperlink – (treated as part of message data)
Web service
input
Operation 1
address, method output
input
Operation 2
address, method output
.
. Hypertext
.
input
Operation n
address, method output
Fig. 22.4 Functional model of RESTful services, with the service, its operations and their input
and output messages
and “Service Description with the Minimal Service Model and RDFa” (page 488))
can be parsed into instances of this RDFS model and stored in a service registry (see
“iServe: A Service Registry” (page 499)) for processing in various types of tools.
On top of the material properties defined in the model above, services, their op-
erations, and messages can also have human-readable names, which can be attached
in RDF using the rdfs:label property. Additionally, it is useful to include an
rdfs:isDefinedBy link from a particular service described with this model
back to the service’s HTML documentation; such a link will allow tools for example
to show the relevant documentation snippets when a user browses the API (this
would be similar to how JavaDoc snippets are shown in Java programming IDEs).
Interoperability with WS– services Note that since WSDL descriptions can
trivially be mapped into the same minimal model, it allows a single client framework
to support WS– and RESTful services without regard to their technological
differences; this is especially true for semantic clients, discussed below in “Service
Semantics with WSMO-Lite” (page 496).
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 483
In the preceding sections of this chapter, we have discussed the structure of RESTful
services, viewed as sets of operations, and we have noted that RESTful services are
universally described with HTML documentation, while providers seem reluctant
to also create and maintain machine-oriented service descriptions for their RESTful
services.
In this section, we introduce hRESTS, a microformat that can be used to
structure the existing RESTful Web service documentation so that the key pieces of
information are machine-processable. Microformats are an “adaptation of semantic
XHTML that makes it easier to publish, index, and extract semi-structured informa-
tion” (Khare and Çelik 2006), an approach for annotating mainly human-oriented
Web pages so that selected information is machine-readable. On top of micro-
formats, GRDDL (Gleaning Resource Descriptions from Dialects of Languages
GRDDL 2007) is a mechanism for extracting RDF information from Web pages,
particularly suitable for processing microformats. For instance, there are already
microformats for contact information, calendar events, ratings etc.
Microformats take advantage of existing XHTML facilities such as the class
and rel attributes to mark up fragments of interest in a Web page, making
the fragments easily available for machine processing. For example, a calendar
484 J. Kopecký et al.
microformat marks up events with their start and end time and with the event title,
and a calendaring application can then directly import data from what otherwise
looks like a normal Web page. Further details on how microformats work can be
found at microformats.org.
The hRESTS microformat is made up of a number of HTML classes that corre-
spond directly to the various parts of the minimal service model. To help illustrate
the detailed definitions of the hRESTS classes, in Listing 22.3 we show hRESTS
annotations of the sample HTML service description shown in Listing 22.1.
In the following detailed definitions, we refer to RDF classes and properties from
the service model (Listing 22.2) using the prefix hr.
The service class on block markup (e.g. <body>, <div>), as shown in the
example listing on line 1, indicates that the element describes a service API. An
HTML element with the class service corresponds to an instance of hr:Serv-
ice. A service contains one or more operations and may have a label (see below).
The operation class, also used on block markup (e.g. <div>), indicates that
the element contains a description of a single Web service operation, as shown
in the listing on line 3. An element with this class corresponds to an instance of
hr:Operation, attached to its parent service with hr:hasOperation. An
operation description specifies the address and the method used by the operation,
and it may also contain description of the input and output of the operation, and
finally a label.
The address class is used on textual markup (e.g. <code>, shown on line 6)
or on a hyperlink (<a href>) and specifies the URI of the operation, or the
URI template in case any inputs are URI parameters. Its value is attached to the
operation using hr:hasAddress. On a textual element, the address value is in
the content; on an abbreviation, the expanded form (the title of the abbreviation)
specifies the address; and on a hyperlink, the target of the link specifies the address
of the operation.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 485
The method class on textual markup (e.g. <span>, shown on line 5) specifies
the HTTP method used by the operation. Its value is attached to the operation using
the property hr:hasMethod.
Both the address and the method may also be specified on the level of the service,
in which case these values serve as defaults for operations that do not specify them.
In absence of any explicit value for the method, the default is GET. The RDF form
of the service model reflects the default values already applied, that is, an instance
hr:Service will never have either hr:hasMethod or hr:hasAddress.
The input and output classes are used on block markup (e.g. <div> but
also <span>), as shown on lines 7 and 13, to indicate the description of the input
or output of an operation. Elements with these classes correspond to instances of
hr:Message, attached to the parent operation with hr:hasInputMessage
and hr:hasOutputMessage respectively.
While the output data format can, in principle, be self-describing through the
metadata the client receives together with the operation response, but it is, in general,
useful for API descriptions to specify what the client can expect; hence the output
class.
The class parameter, an extension of the original hRESTS microformat, is
used on block markup as shown on line 9 to mark the description of a particular
parameter of an input or output message. The class can be complemented with
the class mandatory to indicate that the parameter is mandatory; otherwise
it can be treated as optional. Elements with the parameter class correspond
to instances of hr:MessagePart, attached to the parent input or output with
hr:hasMandatoryPart or hr:hasOptionalPart, depending on the pres-
ence of the class mandatory on the element.
The label class is used on textual markup to specify human-readable labels for
services, operations, messages and their parameters, as shown on lines 2 and 4 in the
example listing. The value is attached to the appropriate service or operation using
rdfs:label.
Additionally, service, operation, message and parameter elements can carry an
id attribute, which is combined with the URI of the HTML document to form the
URI identifier of the particular instance. This will allow other semantic statements
to refer to these instances directly.
The definitions above imply a hierarchical use of the classes within the element
structure of the HTML documentation. The following is a complete list of structural
constraints on the hierarchy of elements marked up with hRESTS classes. It reflects
the structure of our service model, amended with the defaulting of the address
and method properties:
1. No XHTML element with the class service is a descendant6 of an element
with any hRESTS class.
6
The term descendant is defined for XML/HTML elements in XPath (XML Path Language XPath
2009).
486 J. Kopecký et al.
In “Minimal Service Model” (page 480), we have discussed the use of SAWSDL
properties to add semantic annotations to service descriptions. Here, we define a
simple microformat that extends hRESTS to support such semantic annotations.
SAWSDL annotations are URIs that identify semantic concepts and data transfor-
mations. Such URIs can be added to the HTML documentation of RESTful services
in the form of hypertext links. HTML (HTML 4.01 Specification 1999) defines a
mechanism for specifying the relation represented by link, embodied in the rel
attribute; along with class, this attribute is also used to express microformats.
In accordance with SAWSDL, we introduce the following three new types of link
relations:
• Model indicates that the link is a model reference.
• Lifting and lowering denote links to the respective data transformations.
Listing 22.4 illustrates the use of these link relations on semantic annotations
added to the hRESTS description from Listing 22.3. In the detailed definitions
below, we refer to the SAWSDL RDF properties using the prefix sawsdl.7
7
The prefix sawsdl refers to the namespace http://www.w3.org/ns/sawsdl#.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 487
8
A notable new technology for transformations between XML and RDF (either way) is XS-
PARQL (Akhtar et al. 2008), see http://xsparql.deri.org.
488 J. Kopecký et al.
Parsing hRESTS
Alternative to using the hRESTS microformat to capture the service model structure
in the HTML documentation of RESTful Web services, we can also employ
RDFa (RDFa in XHTML: Syntax and Processing 2008) in order to use the RDF
9
http://cms-wg.sti2.org/TR/d12/v0.1/20081202/xslt/hrests.xslt.
10
http://www.w3.org/TeamSubmission/turtle/.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 489
service model directly. RDFa specifies a collection of generic XML attributes for
expressing RDF data in any markup language, and especially in HTML.
Since our service description data is ultimately processed as RDF, RDFa is
directly applicable. In our case, the difference between the use of a microformat
or RDFa boils down to several considerations:
• The microformat syntax is simpler and more compact than RDFa;
• HTML marked up with our microformat remains valid HTML, whereas RDFa
currently only validates against the newest schemas;
• RDFa represents the full concept URIs and thus facilitates the coexistence of
multiple data vocabularies in a single document, where microformats may run
into naming conflicts;
• Processing microformats requires vocabulary-specific parsers (such as our XSLT
transformation described in “Parsing hRESTS” (page 488)), while parsing the
RDF data from RDFa is independent from any actual data vocabularies.
To illustrate the RDFa annotations explained in the following text, Listing 22.6
shows the HTML description from Listing 22.1, annotated with RDFa as data in the
minimal service model; all the extra markup is highlighted in bold.
First, any portion of the HTML document that describes a given part of the
service (an operation, its input our output, or the service as a whole) should be
enclosed in a single HTML container element, such as <body>, <p>, or in a
general-purpose block such as <div> or <span>. In many cases this will already
be so; otherwise the annotator can introduce a new container element with minimal
effect on the presentation of the HTML document in a Web browser. In the listing,
490 J. Kopecký et al.
the added container elements are on lines 1–22 (service), 6–22 (operation), 11–16
(input), and 17–20 (output).
These container elements can then be marked with the RDFa typeof attribute
with the appropriate service model class: hr:Service (line 1), hr:Operation
(line 6), hr:Message (lines 11 and 17), or hr:MessagePart (line 13). To link
a service to its operations, and the operations to their input and output messages,
we use the RDF properties hr:hasOperation, hr:hasInputMessage and
hr:hasOutputMessage in the RDFa rel attribute, as shown on lines 6, 11
and 17. To link message parts to their parent message, we use the RDF properties
hr:hasMandatoryPart (line 13) or hr:hasOptionalPart, as appropriate.
The duplicate <div> and <span> container elements on lines 6, 11, 13 and 17
are required to explicitly type operations and messages with the respective service
model classes. This type information can also be inferred from the RDFS schema of
the service model, so the typeof annotations (and their associated extra container
elements) could potentially be omitted.
Most of the components can also usefully carry human-readable labels, using the
RDFS property rdfs:label in the RDFa property attribute used for textual
properties (see lines 5, 7 and 14; note how identifying the label on line 5 also needed
a <span> wrapper element). Additionally, as shown on line 4, the documentation
should include an rdfs:isDefinedBy link to "" (which means the HTML
document itself).
A description of an operation can specify the URI template and the method where
the operation can be invoked; for this, we use the properties hr:hasAddress and
hr:hasMethod (shown on lines 8 and 9; identifying the method in this example
needed another <span> wrapper).
Listing 22.7 shows the RDF data encoded in Listing 22.6, if that document were
available at http://example.com/api/desc.html.
SAWSDL in RDFa
Listing 22.7 RDF data encoded in Listing 22.6 (in Turtle syntax)
Listing 22.8 Example RDFa service description extended with SAWSDL annotations
492 J. Kopecký et al.
Listing 22.9 Additional RDF data encoded in Listing 22.8 (showing only differences from
Listing 22.7; in Turtle syntax)
In the listing, the new paragraph on lines 7–11 contains a model reference
that associates the service with the concept HotelReservation, which may be in a
taxonomy of service functionalities; and the new link on line 22 represents a model
reference that defines the id parameter to be an instance of the class Hotel.
Lines 24–25 show a link to a lowering transformation. The transformation would
presumably map a given instance of the class Hotel into the ID that the service
expects as a URI parameter.
The SAWSDL properties added in Listing 22.8 are shown in RDF in Listing 22.9.
Note that combined with the contents of Listing 22.7, the RDF data is the same as
that extracted from the microformat version in Listing 22.5.
Notably, an earlier work called SA-REST (Sheth et al. 2007) also used RDFa
to express semantic annotations of services. In contrast with our work presented in
this chapter, SA-REST used a limited implied service model, describing a single
HTTP method on any given resource as an operation, without grouping operations
into services.
In this section, we briefly describe how the lightweight service descriptions can
be used to support automation of the use of RESTful Web services. The aim is
to use semantic technologies to help with the following tasks: discovery matches
known Web services against a user goal and returns the services that can satisfy that
goal; composition puts together multiple services when no single service can fulfill
the whole goal; ranking orders the discovered or composed services based on user
requirements and preferences so the best service can be selected; invocation then
communicates with the service to execute its functionality; and mediation resolves
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 493
any arising heterogeneities. A semantic software system that automates these tasks
acts on behalf of the actual user as a client to the services.
To support such automation, service descriptions need to capture four aspects
of service semantics:11 information model (a domain ontology) represents data,
especially in input and output messages; functional semantics specifies what the
service does; behavioral semantics defines the sequencing of operation invocations
when invoking the service; and nonfunctional descriptions represent service policies
or other details specific to the implementation or running environment of a service.
WSMO-Lite (Fensel et al. 2010) proposes a lightweight ontology for the four
kinds of semantics, shown in Listing 22.10, intended to be combined with SAWSDL
to annotate service descriptions. Informally, the four types of service semantics are
represented in the WSMO-Lite ontology as follows:
• Information semantics are represented using domain ontologies, which are also
involved in the descriptions of the other types of semantics.
• Functional semantics are represented in WSMO-Lite as capabilities and/or
functionality classifications. A capability defines preconditions which must hold
in a state before the client can invoke the service, and effects which hold
in a state after the service invocation. Functionality classifications define the
service functionality using some classification taxonomy (i.e., a hierarchy of
categories).12
• Nonfunctional semantics are represented using an ontology that semantically
captures some policy or other nonfunctional properties.
• Behavioral semantics are represented by annotating the service operations
with functional descriptions, i.e., capabilities and/or functionality classifications.
Functional annotations of operations can then serve for ordering of operation
invocations.
11
The separation of four types of service semantics is inspired by Sheth (2003).
12
The distinction of capabilities and categories is the same that is made by Sycara et al.
(2003) between “explicit capability representation” (using taxonomies) and “implicit capability
representation” through preconditions and effects.
494 J. Kopecký et al.
Fig. 22.5 The structure and use of the WSMO-Lite service ontology, annotating the elements of
the minimal service model
taxonomy, the root class of the taxonomy is an instance of this class. All subclasses
of the root are included in the particular classification. An annotation tool can simply
suggest all functional classification root classes and their subclasses when creating
functional annotations.
wsl:NonfunctionalParameter is a class of concrete, domain-specific non-
functional parameters. For a particular ontology of nonfunctional semantics, its
instances would be instances of this class.13
wsl:Condition, wsl:Effect together form a capability in a functional
service description. Instances of these classes are expected to contain some logical
expressions. The WSMO-Lite service ontology does not specify the concrete
language for the logical expressions, or their processing. Logical expressions can
be specified in any suitable language, such as RIF (RIF Core Dialect 2010),
SWRL (Horrocks 2003), or WSML (The Web Service Modeling Language WSML
2008), and embedded in RDF semantic descriptions as literals.
Now that we have shown the ontology for expressing semantic service descrip-
tions, we briefly discuss several algorithms that can be used by semantic client
software to process WSMO-Lite descriptions to automate some of the tasks involved
in the use of Web services.
The process of using Web services can be split into the following tasks: dis-
covery, negotiation, ranking and selection, composition, mediation and invocation.
Algorithms for automating these tasks have been researched in the area of Semantic
Web Services (SWS); they can commonly be adapted to WSMO-Lite with little
effort.
Since WSMO-Lite semantics is intentionally lightweight, adapting a SWS
automation algorithm may involve filling in concrete details about WSMO-Lite
semantics that are used by the algorithm, effectively refining the semantics defined
by WSMO-Lite. Additionally, an algorithm must also define what kinds of data it
requires from the user to specify a goal. While this means that different algorithms
for the same automation task need not be able to process the same semantic service
and goal descriptions, WSMO-Lite aims to provide a limited common ground for
the various approaches to semantic automation, to facilitate communication between
the often disconnected SWS research groups.
In the rest of this section, we discuss possible algorithms for a few selected tasks,
demonstrating both the use of WSMO-Lite annotations and the refinement of its
semantics.
13
WSMO-Lite does not place any further restrictions on nonfunctional parameters; research in this
area, which is out of scope of this book, has not yet converged on a common set of properties that
nonfunctional parameters should have.
496 J. Kopecký et al.
These tasks mostly deal with the nonfunctional parameters of a service. The user
goal (or general user settings) specifies constraints and preferences (also known
as hard and soft requirements) on a number of different aspects of the discovered
services and offers. For instance, service price, availability and reliability are typical
parameters for services.
Filtering is implemented simply by comparing user constraints with each ser-
vice’s parameter values, resulting in a binary (yes/no) decision. Ranking, however, is
a multidimensional optimization problem, and there are many approaches to dealing
with it, including aggregation of all the dimensions through weighted preferences
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 497
into a single metric by which the services are ordered, or finding locally-optimal
services using techniques such as Skyline Queries (Skoutas et al. 2008).
Selection is then the task of selecting only one of the ranked services. With a total
order, the first service can be selected automatically, but due to the complexity of
comparing the different nonfunctional properties (for instance, is a longer warranty
worth the higher price?), often the ordered list of services will be presented to the
user for manual selection.
Service Composition
14
http://rdfa.info/rdfa-implementations/.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 499
iServe is a public platform16 that unifies service publication and discovery on the
Web through the use of lightweight semantics. The service descriptions published
in iServe are avilable on the Web as RDF, following the principles of Linked
Data (Bizer et al. 2009):
1. Use URIs as names for things.
2. Use HTTP URIs so that people can look up those names.
3. When someone looks up a URI, provide useful information, using the standards
(RDF*, SPARQL).
4. Include links to other URIs, so that they can discover more things.
iServe provides a generic semantic service registry able to support advanced dis-
covery over different kinds of services described using heterogeneous formalisms.
The fundamental objective pursued by iServe is to provide a platform able to publish
service annotations in a way that would allow people to achieve a certain level of
expressivity and refinement when discovering services, while remaining simple and
convenient both for human and machine usage.
Currently iServe provides import support for hRESTS with SAWSDL,17 WSDL
with SAWSDL, and OWL-S (OWL-S 1.1 Release 2004). The mapping from OWL-S
is not lossless, nor is it meant to be. Instead, it extracts the “bare bones” of the
original description that are compatible with the minimal service model, keeping an
rdfs:isDefinedBy link to the original description. This way iServe publishes
service descriptions in the Web of Data in a common way that is amenable to
automated processing; systems optimized for specific formalisms can still obtain
and exploit the original descriptions.
The main components of iServe are a browser GUI, a set of RESTful APIs, a
crawler, a set of import mechanisms, and an RDF store. The iServe browser GUI,
shown in Fig. 22.6 is a Web-browser-based application that is the main human-
oriented interface of the registry. The RESTful APIs provide support for accessing
and submitting service annotations and service documentation, along with several
types of semantic discovery, as detailed below. The crawler takes care of collecting
existing annotations from the Web in order to publish them in iServe. Using the
15
http://soa4all.eu.
16
Located at http://iserve.kmi.open.ac.uk/.
17
iServe import support for the RDFa form described in “Service Description with the Minimal
Service Model and RDFa” (page 488) is planned.
500 J. Kopecký et al.
Fig. 22.6 A screenshot of the iServe browser GUI, showing service categorizations on the left, a
list of services in the top-right part, and the details of a selected service in the bottom-right part
crawler, iServe has imported several known large sets of service annotations, such
as the SAWSDL and OWL-S test collections.18 The import mechanisms process
submitted descriptions in diverse formalisms by transforming them into the minimal
service model. Finally, the RDF store manages all the service description and
annotation data along with some provenance metadata; it also provides a SPARQL
endpoint for advanced data access.
18
http://www.semwebcentral.org/projects/owls-tc/, http://www.semwebcentral.org/projects/sawsd
l-tc/.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 501
whereas the third uses information retrieval techniques that avoid strict logical false
negatives.
The discovery mechanisms offered by iServe are available as part of the registry’s
RESTful API as follows:
/data/disco/func-rdfs?class=C1&class=C2 &...
uses RDFS functional classification annotations and returns those services that
are related to all the functional categories Ci (which are URIs).
/data/disco/io-rdfs?f=fand|org&i=C1I &i=C2I &o=C1O &...
uses ontology annotations of inputs and outputs and returns services for which
the client has suitable input data (CiI ) and/or (depending on the parameter f for
function) which provide the outputs requested by the client (CiO ).
/data/disco/imatch?strategy=levenshtein&label=L
returns all services ranked according to string similarity of the service label with
the string L.
In the spirit of using Web standards, the API represents discovery results as Atom
feeds,19 with the entries representing matching services sorted by matching degree.
The Atom feed format was chosen for several reasons: it is a standard generic
container format with wide support in software libraries and products, and it defines
strong metadata properties (such as titles, identities and update times) that make feed
readers a meaningful standalone software category. With Atom, iServe discovery
queries can, for example, be syndicated and manipulated in generic systems such as
Yahoo! Pipes,20 or end users can watch for new interesting services by registering
iServe discovery queries in their feed readers.
The common representation of discovery results as Atom feeds can be exploited
for supporting arbitrary combinations of discovery approaches through list opera-
tions on the results of separate discovery queries. iServe includes three Atom feed
combinators:
1. Union: the resulting feed contains the entries of all the constituent feeds. For
discovery queries, the union of results is equivalent to the or (disjunction)
operator: a service is returned if it matches any of the given queries.
2. Intersection: results in a feed with only the entries present in all the constituent
feeds. This is equivalent to the and (conjunction) operator for discovery queries.
3. Subtraction: results in a feed with the entries of the first feed that are not in any
other provided feed. In discovery, this enables the and not operator: it can return
services that match one query but not another.
All these combinators are part of iServe’s RESTful API, and they take feed
URIs as parameters. To illustrate the use of the discovery API, including the Atom
combinators, the following URI would discover proximity search services that take
as inputs a raw address (proximity search and raw address are terms in an ontology
used to annotate a set of geography services present in iServe):
http://iserve.kmi.open.ac.uk/data/atom/intersection?
f=/data/disco/func-rdfs?class=
http://iserve.kmi.open.ac.uk/2010/05/s3eval/func.rdfs%2523ProximitySearch
&f=/data/disco/io-rdfs?
i=http://iserve.kmi.open.ac.uk/2010/05/s3eval/data.rdfs%2523RawAddress
The example contains altogether five URIs: the location of the intersection
combinator, the location of the RDFS functional classification discovery service
(note that the URI is relative to the atom combinator URI), the identifier of a class
of proximity search services, the location of the RDFS input/output matchmaker and
the identifier of the concept of a raw address. Note how the nesting of URIs requires
careful percent-encoding of special characters (such as the hash sign “#” encoded
as “%23”, which is then encoded again as “%2523” – “%25” is the percent-sign –
because the URI is nested in two others).
The separation of the individual discovery algorithms from the mechanism by
which they are combined supports easy extensibility: new discovery algorithms can
be added to iServe independently (as plug-ins) and then usefully combined with the
algorithms that are already there.
21
Available at http://sweet.kmi.open.ac.uk/.
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 503
in the insert hTags pane. In the beginning, only the Service node of the hRESTS tree
is enabled. After the user marks the body of the service description, additional tags
are enabled. In this way, SWEET guides the user through the process of marking
parts of the service description with hRESTS tags. The marking of HTML content
with a particular hRESTS tag results in the insertion of a corresponding class
HTML attribute, and is reflected in the Semantic Description panel. In addition,
each inserted tag is highlighted to visualize the annotations.
When the HTML documentation is ready with a machine-processable hRESTS
service model structure, the user can start adding semantic annotations. SWEET
supports users in searching for suitable ontologies by providing an integrated search
with Watson.22 The user selects a part of the service description and the system
then retrieves matching ontology entities from Watson, displaying them in the
Service Properties and Domain Ontologies panels visualized in Fig. 22.8. Using the
information in these panels, the user can choose a suitable ontology for annotating
the API description.
By using Watson, SWEET assists users in locating appropriate annotations from
among the existing ontological data on the Web, fostering ontology reuse.
Having chosen an appropriate ontology, the user can again pick parts of the
service HTML description and add concrete semantic annotations through the
context menu in the Service Properties panel. This results in inserting a model
reference pointing to the URI of the selected semantic entity. The Annotations panel
summarizes the already made annotations and makes it possible to delete them.
22
Watson Semantic Web Search, http://watson.kmi.open.ac.uk.
504 J. Kopecký et al.
When the user completes the semantic annotation of the HTML description, the
result can be saved locally or it can be directly published in the iServe registry.
In summary, Web API providers or interested third parties can use SWEET as a
user-friendly way of preparing machine-processable service descriptions, enabling
tool support for discovery and so on. SWEET minimizes the effort involved in
editing service descriptions, especially since it starts with the already-existing Web
API documentation.
Summary
In this chapter, we have tackled the need for machine-processable service descrip-
tions for RESTful services and Web APIs, in face of the reluctance of service
providers to publish descriptions in languages such as WSDL and WADL.
The minimal service model presented in this chapter views services as sets of
operations; while it disregards resources, we have argued that it is nevertheless a
natural model for client-side tool support.
The service model can be applied to existing service documentation in HTML,
using either the microformat hRESTS, or using RDFa, a generic extension of HTML
for including RDF data. Either way, the human-oriented service documentation be-
comes a machine-processable service description with no repetition of information,
and with minimal changes to the actual presentation of the documentation.
Having machine-processable service description is a prerequisite for adding se-
mantic annotations that can support a degree of automation of service discovery and
22 RESTful Services with Lightweight Machine-readable Descriptions. . . 505
Acknowledgments The authors would like to thank Dr. Karthik Gomadam for collaboration on
the hRESTS microformat. Much of the work presented in this chapter has been supported by the
European Union research project SOA4All http://www.soa4all.eu.
References
Akhtar, W., Kopecký, J., Krennwallner, T., Polleres, A.: XSPARQL: Traveling between the XML
and RDF worlds – and avoiding the XSLT pilgrimage. In: S. Bechhofer, M. Koubarakis (eds.)
The Semantic Web: Research and Applications, 5th European Semantic Web Conference,
ESWC 2008, Lecture Notes in Computer Science, LNCS, vol. 5021, pp. 674–689. Springer,
Tenerife, Spain (2008)
Akkiraju, R., Farrell, J., Miller, J., Nagarajan, M., Schmidt, M., Sheth, A., Verma, K.: Web
Service Semantics – WSDL-S. Technical note (2005). Available at http://lsdis.cs.uga.edu/
library/download/WSDL-S-V1.html
Architecture of the World Wide Web. Recommendation, W3C (2004). Available at http://www.w3.
org/TR/webarch/
Bizer, C., Heath, T., Berners-Lee, T.: Linked Data - The Story So Far. International Journal on
Semantic Web and Information Systems (IJSWIS), Special Issue on Linked Data (2009)
Fensel, D., Fischer, F., Kopecký, J., Krummenacher, R., Lambert, D., Vitvar, T.: WSMO-
Lite: Lightweight Semantic Descriptions for Services on the Web (2010). URLhttp://www.
w3.org/Submission/WSMO-Lite/. W3C member submission, available at http://www.w3.org/
Submission/WSMO-Lite/
Gleaning Resource Descriptions from Dialects of Languages (GRDDL). Recommendation, W3C
(2007). Available at http://www.w3.org/TR/grddl/
Hoffmann, J., Weber, I., Scicluna, J., Kaczmarek, T., Ankolekar, A.: Combining Scalability and
Expressivity in the Automatic Composition of Semantic Web Services. In: Proceedings of the
8th International Conference on Web Engineering (ICWE’08). Yorktown Heights, USA (2008)
Horrocks, I., Patel-Schneider, P.F., Boley, H., Tabet, S., Grosof, B., Dean, M.: SWRL: A Semantic
Web Rule Language Combining OWL and RuleML. Tech. rep., Joint US/EU ad hoc Agent
Markup Language Committee (2003). Available at http://www.daml.org/2003/11/swrl/
HTML 4.01 Specification. Recommendation, W3C (1999). Available at http://www.w3.org/TR/
html401
Khare, R., Çelik, T.: Microformats: a pragmatic path to the semantic web (Poster). Proceedings of
the 15th international conference on World Wide Web pp. 865–866 (2006)
OWL Web Ontology Language Overview. Recommendation 10 February 2004, W3C (2004).
Available at http://www.w3.org/TR/owl-features/
506 J. Kopecký et al.
OWL-S 1.1 Release. Tech. rep., OWL Services Coalition (2004). Available at http://www.daml.
org/services/owl-s/1.1/
RDFa in XHTML: Syntax and Processing. Recommendation, W3C (2008). Available at http://
www.w3.org/TR/rdfa-syntax/
Richardson, L., Ruby, S.: RESTful Web Services. O’Reilly Media (2007)
RIF Core Dialect. Recommendation, W3C (2010). Available at http://www.w3.org/TR/rif-core/
Semantic Annotations for WSDL and XML Schema. Recommendation, W3C (2007). Available at
http://www.w3.org/TR/sawsdl/
Sheth, A.P.: Semantic Web Process Lifecycle: Role of Semantics in Annotation, Discovery,
Composition and Orchestration (2003). Invited Talk, Workshop on E-Services and the Semantic
Web, at WWW 2003. Available at http://lsdis.cs.uga.edu/lib/presentations/WWW2003-ESSW-
invitedTalk-Sheth.pdf
Sheth, A.P., Gomadam, K., Lathem, J.: SA-REST: Semantically Interoperable and Easier-to-Use
Services and Mashups. IEEE Internet Computing 11(6), 91–94 (2007)
Skoutas, D., Sacharidis, D., Simitsis, A., Sellis, T.: Serving the Sky: Discovering and Selecting
Semantic Web Services through Dynamic Skyline Queries. In: Proceedings of the 2008 IEEE
International Conference on Semantic Computing. Santa Clara, USA (2008)
Sycara, K., Paolucci, M., Ankolekar, A., Srinivasan, N.: Automated discovery, interaction and
composition of Semantic Web services. Web Semantics: Science, Services and Agents on the
World Wide Web 1(1), 27–46 (2003)
The Web Service Modeling Language WSML. Tech. rep., WSMO Working Group (2008).
Available at http://www.wsmo.org/TR/d16/d16.1/v1.0/
Web Services Description Language (WSDL) Version 2.0: Adjuncts. Recommendation, W3C
(2007). Available at http://www.w3.org/TR/wsdl20-adjuncts/
XML Path Language (XPath) Version 1.0. Recommendation, W3C (2009). Available at http://
www.w3.org/TR/xpath
Chapter 23
Towards Distributed Atomic Transactions over
RESTful Services
Introduction
The Uniform Interface (Fielding 2000) of a RESTful Web service (Richardson and
Ruby 2007) implemented using HTTP has very useful and positive implications on
the reliability of the interaction of clients with a service following the constraint.
Considering that GET, PUT, DELETE requests are by definition idempotent, any
failure during these interactions can be addressed by simply repeating the request.
This property, however, cannot be directly applied in a service composition
scenario (Pautasso 2009) where multiple interactions between a set of RESTful
services need to happen atomically. Even if a single idempotent interaction between
one client and one RESTful Web service is reliable, it is not clear how to guarantee
the same property of atomicity when a client is interacting with multiple RESTful
Web services. This problem is the central topic of this chapter, and will be discussed
by means of the running example illustrated in the following section.
G. Pardon ()
ATOMIKOS, Hoveniersstraat 39/1, 2800 Mechelen, Belgium
e-mail: [email protected]
Suppose we want to book a flight composed of two connecting flights from two
different and autonomous airlines: swiss.com and easyjet.com, via some travel
agency service acting as a service composition over the two airlines. Let’s assume
that both airlines have the same hypermedia contract for bookings (for reasons of
simplicity, and without loss of generality since the composite service is supposed to
know all of the hypermedia contracts involved). The REST implementation of the
airline information and booking services could be designed as follows.
Clients can inquire about the availability of seats on a flight at the URI:
/flight/fflight-nog/seat/fseat-nog. For example, the GET/flight
/LX101/seat/ request will return a hyperlink to the next available seat on the
flight LX101 or none (e.g., 204 No Content) if the flight is fully booked.
Booking a Seat
A POST request to the /booking URL with a payload referencing such seat will
create a new booking resource and redirect the client to it by sending a hyperlink
identifying it such as /booking/fidg/. The body of the request can contain
a reference to the chosen flight and seat (i.e., <flight number="LX101"
seat="33F"/>). The booking can be updated with additional information using
a PUT/booking/fidg/ request.
Composition of Bookings
We are now ready to present the first user story, which will be our motivating
example throughout this chapter.
Story 1 As a customer, I want to book a composed flight consisting of two
independent, connecting flights from both airlines.
The problem is that it may happen that after the first airline service has
successfully performed the booking (step 2), the second airline may reply that there
are no seats available. Thus we have only a partial flight.
Even if we reorder the requests as follows:
1. GET swiss.com/flight/LX101/seat/
2. GET easyjet.com/flight/EZ222/seat/
3. POST swiss.com/booking
4. POST easyjet.com/booking
the problem is not solved. Even if both step 1 and 2 may return a link to an available
seat, the following booking requests may fail due to concurrent intermediate
bookings. Thus, we may still end up in a situation where we have reserved one flight
but not the other one. If 3 fails (due to, say, intermediate bookings at easyjet.com
between steps 2 and 4) then we have one flight but not the other one. The retry of
individual requests does not help here: we can try to repeat step 4 as many times as
we like, but if the flight is fully booked then we will keep getting the same failure
each time. What we really need is the ability to make step 3 and 4 tentative, so
that they can be confirmed later. This way the whole process becomes atomic and
happens entirely or not at all.
The goal of this chapter is to propose a solution to the problem of atomicity within
distributed RESTful interactions within the constraints of: (a) Using a lightweight
transaction model (Pardon and Alonso 2000) based on ATOMIKOS TCC (Pardon
2009); (b) Minimizing, or in the best case, avoiding changes to the REST uniform
interface and the HTTP protocol. (c) Assigning to the service running the composi-
tion the responsibility of ensuring the atomicity of the transaction.
A solution should provide the ability to transparently group multiple RESTful
interactions and treat them as a single logical step, as well as to ensure that the
consistency of a set of resources which are distributed over multiple servers can
be kept. Whereas solutions have been proposed to batch interactions affecting
multiple resources provided by a single server [e.g., WebDAV’s explicit lock-
ing methods (Goland et al. 1999), or the transactions as a resource approach
from (Richardson and Ruby, 2007, p. 231)], these are not directly applicable to
interact with multiple resources distributed across multiple servers.
Whether or not REST needs transactions has been heavily debated within the REST
community (Little 2009). We claim there is a clear need, and we try to motivate it
here. Our motivation is in two parts. First, we define a business model for RESTful
services that needs transactions. Next, we define the technical qualities that we think
a transaction model for REST should possess in order to be successful.
With the first story we have already motivated the need for atomicity, and why
idempotent requests are not enough. We will now refine this model based on realistic
business needs of each of the parties involved.
The travel agency can now implement a transactional booking as shown by Fig. 23.1.
In terms of design, the first set of interactions can be driven by the workflow that
composes the two services, while the final confirmations to close the transaction
could be sent to a transaction coordinator component.
Let’s return to the original problem: what if step 4 (i.e., the second booking) fails?
By not performing any confirmation, the workflow engine ensures that no billing is
done for either flight. This avoids our original problem as the transaction coordinator
will not confirm any of the bookings.
Confirmation is driven by the needs of the customer and the travel agency that
composes the individual services. From the point of view of the airlines, an
additional story arises:
Story 3 As an airline, I do not want to wait for a confirmation forever. In other
words, I want to be able to autonomously cancel a pending booking after some
timeout expires.
This should be obvious: as an airline, I do not want to loose money because some
travel agency keeps seats reserved without confirmations. Consequently, we need a
cancellation event triggered by some timeout specific to the airline.
512 G. Pardon and C. Pautasso
Generalisation: Try-Cancel/Confirm
Industry practice has shown that transactions need to be non-invasive or they will
be avoided. This is mostly due to the tight coupling and the additional complexity
they introduce in the design and implementation of services which can participate
in a transaction.
Our simple proposal attempts to avoid the negative impacts of existing ap-
proaches while ensuring that the visibility and the interoperability that have come
to be expected of RESTful services are not affected.
Loose Coupling
additional coupling among them. This is important to remain within the scope of the
REST constraints which emphasize the role of the client as the one driving forward
the state of an application.
A transaction solution for REST is considered loosely-coupled (Pautasso and
Wilde 2009) if participating services are unaware of the fact that they are being
part of a global transaction. More precisely: the individual participating services
do not need to have any additional knowledge or implement any extra protocols
besides what they already support. Whereas not all RESTful services may be able
to participate in such transactions, we claim that there is a significant number of
resources that naturally fit with our assumptions due to the nature of the business
service they implement. This is particularly true for services that comply with the
TCC business model outlined in the previous section.
No Context Please
The classical ACID transaction paradigm revolves around database locks and low-
level rollback at the database level (Bernstein et al. 1987; Gray and Reuter 1993).
Distributed ACID transactions (i.e., involving more than one database backend
and/or service) usually require a “distributed transaction coordinator” to drive the
individual ACID transactions via the XA protocol.
A lot has been said about the blocking nature of XA (Open Group 1992) and
two-phase commit in classic ACID transaction technology – we will not repeat that
here. Suffice it to say: any successful transaction technology for SOA should avoid
the distributed locks associated with XA. The most natural way of doing this is with
TCC (Pardon 2009). Instead of introducing long-running ACID transactions, this
allows us to use multiple, short-lived ACID transactions for each of the resource
state transitions triggered by the “try”, “cancel” and “confirm” events (Fig. 23.2). In
addition to avoiding lots of problems, service-specific confirm and cancel logic are
514 G. Pardon and C. Pautasso
also natural with respect to the business model of the service provider. This in turn
means that transaction models embracing these will be less invasive and therefore
more likely to be used.
Protocols
Recovery Protocol
The basic protocol is very simple so it is natural to ask how this can work even in
the presence of failures and recovery. Recovery is outlined below. We assume that
each party is able to restore its own durable state, so we focus on the recoverability
of the atomicity property across all parties.
23 Towards Distributed Atomic Transactions over RESTful Services 515
Defining Recovery
Coordinator Recovery
Like the participant service, we assume that the coordinator service is capable
of restoring its durable state. Consequently, we focus on the recoverability of
the overall atomicity. The coordinator has a slightly more complex job than the
participants, because it has to make sure that all the participants will eventually
arrive at the same end state for the transaction T . In particular, step 4 actually
involves multiple participants so a failure during step 4 could be problematic1. We
propose a naive protocol here, and leave optimisations to future work.
1. For recovery before step 2, do nothing.
2. For recovery between steps 2 and 4: do nothing.
3. For recovery after step 4: do nothing.
4. For recovery during step 4: retry Ri;confirm with each participating service Si .
Since Ri;confirm are performed using idempotent methods, they may be retried as
many times as necessary. Note: this requires the coordinator to durably log all
participant information before starting step 4.
Discussion
Even if there are arbitrary failures, we still preserve atomicity – eventually. In other
words: given enough time, the global transaction T will be confirmed everywhere,
or cancelled everywhere, or nothing will have happend in the first place. More
precisely: either all Ri are confirmed, or all are cancelled. In order to prove this,
we take a closer look at the protocol steps from the point of view of the coordinator.
Here is our proof:
1. If there are no failures, then steps 1–4 run through and each Ri will have been
confirmed.
2. For any failures before step 2, no Ri exists, meaning that nothing has happened.
3. For any failures during or after step 2 but before step 4: all Ri will eventually be
cancelled autonomously by each Si (since nothing has been confirmed yet).
1
Especially because the participants are not aware that they are part of a transaction
23 Towards Distributed Atomic Transactions over RESTful Services 517
4. For any failures during step 4: the coordinator will retry each Ri;confirm until it
succeeds. Because confirmation is idempotent, this will eventually succeed (note:
there is one caveat here – discussed next).
5. For any failures after step 4: all Ri;confirm have been done, so we already have
atomicity and no action is required.
There is one weak spot in our proof of atomicity: during step 4, some service Si may
time out and cancel on its own, while the coordinator is performing confirmation.
In the worst case, this means that some participants confirm whereas others cancel
on their own – effectively breaking atomicity. We call this a heuristic exception for
reasons outlined in the following.
There has been a lot of interesting work related to atomicity, and the more general
problem of distributed agreement, and the most important result is that a perfect
solution is not possible (Fischer 1985). In practice, this means that there is always
the possibility that at least one participating service/node is unaware of the outcome
of the “global” distributed transaction - be it with our TCC protocol for RESTful
Web services or with classic, ACID, XA-style transactions.
The practical consequence is that one or more nodes can remain “in-doubt” about
the global result of one or more business transactions that they are participating in.
For instance, flight reservations may never complete because payment never arrives
(either due network failures, node failures or both).
This is not specific to REST or WS-*, it exists in any networked environment:
there is no perfect protocol for distributed agreement. This is a limitation one has to
live with (and one of the drivers behind the CAP theorem Brewer 2000).
Enter Heuristics
The bottom line is that perfect atomicity may not be possible sometimes, and we
need a practical way of dealing with such scenarios (just like workflow-based solu-
tions do). We propose a simple way based on the “heuristic exceptions” known from
the industry’s two-phase commit protocol families (such as OTS Ram et al. 1999).
In practice, most industrial distributed two-phase commit (2PC) technologies
recognize that similar anomalies may happen. In order to avoid that a participant
518 G. Pardon and C. Pautasso
remains in-doubt about the outcome, these protocols allow the participants to
timeout and unilaterally terminate their part of the a global transaction with a so-
called “heurisitic decision” (e.g., heuristic rollback).
Once a participant completes Ri , it can be considered in-doubt: all its durable state
changes are on disk, and the only remaining thing is the pending confirmation
Ri;confirm on behalf of T . If the participant decides to time-out then this is similar
to what classical two-phase commit calls a heuristic rollback. The default way of
handling this is very similar: we make sure that the coordinator logs this fact on
behalf of T and assume that this will be reported in some implementation-specific
way to allow for out of band manual resolution of the inconsistency by a human
operator.
One big advantage our protocol offers (compared to classical heuristic cases) is the
fact that it offers higher-level semantics and does not hold low-level database locks.
In-doubt participants do not block any other work other than the one affected by
the business resources they reserve on behalf of T . When a heuristic cancel is done
by Si , the consequences are well-defined and known to the business: it corresponds
to a unilateral breach (by Si ) of the contract entered into with the execution of
Ri . Both the coordinator of T and the site administrators at Si can use the high-
level information to manually resolve the inconsistency. Contrast this to classical
transactions, where heuristic exceptions are very low-level error conditions with
vague impact and little context information. In this way, our protocol embraces the
fact that distributed agreement between businesses is challenging due to the inherent
limitations of distributed agreement and the CAP theorem.
We have presented a simple protocol that ensures atomicity in at least as many cases
as ACID transactions do, without the restrictions. However, there is a lot of room
for optimisation. We can see at least the following things to refine:
1. Optimising the basic protocol with coordinator-driven cancellation in addition
to confirmation. This allows the application/workflow to signal failures early,
so that participating services do not have to time out. This in turn minimises
resource contention.
23 Towards Distributed Atomic Transactions over RESTful Services 519
Related Work
REST-*
The recently appeared book “REST in Practice” (Webber et al. 2010) also has a
dedicated chapter discussing transaction support for REST. The approach seems
similar to what REST-* is trying to accomplish, with the same drawback of tight
coupling due to, among other things, a transaction context going all around.
More in detail, the JBoss REST-* initiative aims at providing various QoS
guarantees for RESTful Web services, in much the same way as WS-* has done
for Web services by creating a “stack” of agreed upon best practices and standards
for REST middleware. In its attempt at offering transactions, REST-* follows an
approach that is reasonably close to TIP and WS-AT: a context is added to each
invocation in order to make the invocation transactional. The receiving service has
to understand that context in order to participate in the transaction outcome. This
leads to tight coupling, something that we have tried to avoid.
ATOM Pub/Sub
TIP
The TIP (Transaction Internet Protocol) was one of the first initiatives to offer
reliability on the wider scale of the Internet (Vogler et al. 1999), and across different
23 Towards Distributed Atomic Transactions over RESTful Services 521
CORBA OTS
Within the CORBA ecosystem (Henning 2006), the OTS (Object Transaction
Service) is a distributed transaction framework that (at least in theory) provides
interoperability of transactions across CORBA objects and even across ORBs (Ram
et al. 1999). It is used primarily in financial and telecom industries and it allows for
a certain heterogeneity. However, as every system based on binary ORB protocols
and bindings, CORBA/OTS cannot be directly reused in the domain of RESTful
Web services.
WS-*
The WS-* stack would not have earned its fame if it did not offer some
form of transaction support. A number of competing standards have been
proposed (Zimmermann et al. 2007), but all of them were designed by committee.
This implies that they all tend to be somewhat over-engineered, and above all they
are driven by technology vendors (Tai et al. 2004) rather than by practical needs or
demands. Consequently, their practical relevance is rather limited.
The two most common approaches are the following: WS-AT and WS-BT. We
will discuss them starting from the assumption that the main value proposition of the
WS-* technology stack lies in its intrinsic interoperability between heterogeneous
platforms.
Web Service – Atomic Transactions (WS–AT) is the WS-* counterpart of the
classical ACID transaction technologies. It offers distributed XA transactions over
web service protocols.
As far as we know, this is the only transaction standard that enjoys real cross-
vendor support from the bigger players like IBM and Microsoft. Unfortunately,
this complex specification leads to tight coupling between participating sites.
Configuration is not easy, especially if security is involved. Interoperability among
existing implementations has also been difficult to achieve.
Web Service – Business Activity (WS–BA) is a compensation-based protocol
that arose out of the BPEL world as a way to make BPEL engines coordinate com-
pensation scopes across vendors/engines. It offers the possibility to “compensate”
for unrightfully executed work with application-level callbacks. However, there is
no notion of a business-level “confirmation” phase, which may be needed to address
our requirements.
We do not know of many vendors who support this standard. Microsoft, for
instance, does not. This makes the usefulness for interoperability rather limited and
hence the relevance of this technology may be questionable.
522 G. Pardon and C. Pautasso
XA Technology
Try Confirm/Cancel
Conclusion
2
A similar idea (but lacking the “try” phase) was also proposed in the OASIS BTP proposal (Dalal
et al. 2003), which was standardized but remains without any current implementations.
23 Towards Distributed Atomic Transactions over RESTful Services 523
References
Philip A. Bernstein, Vassos Hadzilacos, and Nathan Goodman. Concurrency Control and Recovery
in Database Systems. Addison-Wesley, 1987.
Eric A. Brewer. Towards robust distributed systems (abstract). In Proc. of the 19th Annual ACM
Symposium on Principles of Distributed Computing, page 7, Portland, Oregon, July 2000.
Sanjay Dalal, Sazi Temel, Mark Little, Mark Potts, and Jim Webber. Coordinating Business
Transactions on the Web. IEEE Internet Computing, 7(1):30–39, January 2003.
Roy Fielding. Architectural Styles and The Design of Network-based Software Architectures. PhD
thesis, University of California, Irvine, 2000.
Michael J. Fischer, Nancy A. Lynch, and Michael S. Paterson. Impossibility of distributed
consensus with one faulty process. J. ACM, 32(2):374–382, 1985.
Yaron Y. Goland, E. James Whitehead, A. Faizi, S. Carter, and D. Jensen. HTTP Extensions for
Distributed Authoring — WebDAV. Internet RFC 2518, February 1999.
Jim Gray and Andreas Reuter. Transaction Processing: Concepts and Techniques. Morgan
Kaufmann, 1993.
Pat Helland. Life beyond Distributed Transactions: an Apostate’s Opinion. In Third Biennial
Conference on Innovative Data Systems Research (CIDR 2007), pages 132–141, Asilomar,
CA, January 2007.
Michi Henning. The Rise and Fall of CORBA. ACM Queue, 4(5):28–34, June 2006.
Mark Little. REST and transactions?, 2009. http://www.infoq.com/news/2009/06/rest-ts.
Alexandros Marinos, Amir R. Razavi, Sotiris Moschoyiannis, and Paul J. Krause. RETRO: A
Consistent and Recoverable RESTful Transaction Model. In Proc. of the IEEE International
Conference on Web Services (ICWS 2009), pages 181–188, Los Angeles, CA, USA, July 2009.
Open Group. Distributed TP: The XA Specification, February 1992.
Guy Pardon. Try-Cancel/Confirm: Transactions for (Web) Services, 2009. http://www.atomikos.
com/Publications/TryCancelConfirm.
Guy Pardon and Gustavo Alonso. CheeTah: a Lightweight Transaction Server for Plug-and-Play
Internet Data Management. In Proceedings of 26th International Conference on Very Large
Data Bases (VLDB 2000), pages 210–219, Cairo, Egypt, September 2000.
Cesare Pautasso. BPEL for REST. In 7th International Conference on Business Process Manage-
ment (BPM08), Milan, Italy, September 2008.
Cesare Pautasso. Composing RESTful Services with JOpera. In Proc. of the International
Conference on Software Composition (SC09), pages 142–159, Zurich, Switzerland, July 2009.
Cesare Pautasso and Erik Wilde. Why is the Web Loosely Coupled? A Multi-Faceted Metric for
Service Design. In Proc. of the 18th International World Wide Web Conference, pages 911–920,
Madrid, Spain, May 2009.
Prabhu Ram, Lyman Do, Pamela Drew, and Tong Zhou. Object Transaction Service: Experiences
and Open Issues. In International Symposium on Distributed Objects and Applications (DOA
1999), pages 296–304, Edinburgh, UK, September 1999.
Amir R. Razavi, Alexandros Marinos, Sotiris Moschoyiannis, and Paul J. Krause. RESTful
Transactions Supported by the Isolation Theorems. In ICWE’09, pages 394–409, 2009.
Leonard Richardson and Sam Ruby. RESTful Web Services. O’Reilly, May 2007.
Florian Rosenberg, Francisco Curbera, Matthew J. Duftler, and Rania Kahalf. Composing RESTful
Services and Collaborative Workflows. IEEE Internet Computing, 12(5):24–31, September-
October 2008.
Stefan Tai, Thomas Mikalsen, Eric Wohlstadter, Nirmit Desai, and Isabelle Rouvellou. Transaction
policies for service-oriented computing. Data Knowl. Eng., 51(1):59–79, 2004.
Steve Vinoski. Serendipitous Reuse. IEEE Internet Computing, 12(1):84–87, 2008.
Hartmut Vogler, Marie-Luise Moschgath, Thomas Kunkelmann, and J. Grünewald. The Transac-
tion Internet Protocol in Practice: Reliability for WWW Applications. IEEE Computer Society,
Internet Workshop’99 (IWS’99), February 1999.
Jim Webber, Savas Parastatidis, and Ian Robinson. REST in practice. O’Reilly, September 2010.
524 G. Pardon and C. Pautasso
Xiwei Xu, Liming Zhu, Yan Liu, and Mark Staples. Resource-Oriented Architecture for Business
Processes. In Proc of the 15th Asia-Pacific Software Engineering Conference (APSEC2008),
December 2008.
Olaf Zimmermann, Jonas Grundler, Stefan Tai, and Frank Leymann. Architectural Decisions and
Patterns for Transactional Worlflows in SOA. In Proc. of the 5th International Conference on
Service-Oriented Computing, Vienna, Austria, 2007.
Index
A B
Abdera, 374–375 Binding, 6, 7, 10, 38, 39, 48, 210, 227, 228,
ACID. See Atomicity, consistency, isolation, 230, 231, 234, 277, 344, 363, 387, 402,
durability (ACID) 404, 405, 421, 480, 521
Adaptation, 230, 402, 405–406 BPEL for REST extensions, 519
Alquimia, 353, 354 Browsing, 240, 242, 292, 304, 305, 313–315,
Application, 1, 30, 37, 61–90, 94, 117, 138, 317, 366, 369, 375, 378
161, 199–218, 221, 237, 272, 279, 304, Business integration, 368
319, 339, 360, 382, 402, 428, 441, 460,
510
Application state, 3, 5, 10, 32, 33, 37, 45, 61, C
64–69, 73, 77, 78, 82, 85, 86, 89, 90, Cache, 22, 44, 46, 52, 72, 73, 83, 163, 164,
93, 94, 96, 97, 117, 119, 123, 126, 143, 166–167, 170, 171, 173, 174, 184–186,
180–183, 190, 192, 244, 248–252, 255, 188, 191–194, 231, 345–347, 460
324, 338, 347, 350, 354, 364, 408, 463, Caching, 42, 46–50, 52, 72–74, 77, 82, 218,
474 243, 248, 343, 345, 347, 351, 373, 384,
Architectural decision, 11, 21, 25, 26, 29, 39 407, 477
Architectural pattern, 341, 342 Client/server, 22, 23, 25, 37, 166–167, 180,
Architectural properties, 23–25 266, 343, 349, 352, 404
Architectural qualities, 341 Cloud, 13, 62, 71, 319, 323
Architectural style, 3, 7–10, 12, 14–16, 21–33, Community, 13, 14, 17, 52, 55, 64, 68, 69, 182,
35–37, 40, 55, 93, 96, 97, 117, 140, 213, 214, 319–338, 360, 373, 376, 378,
142, 144, 194, 199, 200, 208, 217, 221, 427, 429, 442, 447, 464, 468, 510, 519
227, 230, 231, 256, 280, 282, 286, Composition, 7, 262, 267, 298, 316, 402, 412,
339, 341–344, 347, 352, 354, 364, 382, 413, 415–421, 445, 454, 474, 477,
402–411, 416, 421, 441, 457, 459, 475, 483, 492, 495, 497, 498, 507–509,
519 512, 519
Atom, 40, 48, 62, 69–71, 97, 101, 103, 104, Constraints, 2–9, 11, 14, 22, 23, 25, 29–33,
106–107, 109, 168, 169, 248, 263, 265, 50, 55, 61, 69, 132, 140, 161–170, 172,
269, 270, 272, 274, 275, 349, 354, 177, 179–184, 189–191, 194, 203, 250,
369–370, 374, 375, 425, 426, 431, 432, 256, 257, 260, 262, 265–267, 269, 275,
461, 464, 467, 468, 501, 502 278, 339–345, 347, 348, 354, 361, 364,
Atomicity, consistency, isolation, durability 370, 372–374, 378, 403, 406, 412, 485,
(ACID), 340, 513, 517, 518, 521, 522 496, 507, 509, 512, 513, 522
Context, 3, 32, 62, 125, 143, 166, 201, 210, HTTP idioms, 62, 63, 65, 69, 71–73, 77
221, 243, 274, 298, 304, 335, 341, 361, HTTP Methods: (GET, POST, PUT, DELETE),
383, 402, 425, 459, 503, 510 42, 47, 118, 121, 122, 290, 450, 480
Create, retrieve, update and delete (CRUD), HTTP Methods: (PATCH), 45, 52
10, 42, 44, 45, 65, 66, 68, 117–134, HTTP Protocol, 16, 17, 100, 101, 204, 208,
282, 284–286, 290, 291, 293, 297, 312, 218, 306, 313, 345, 364, 378, 383, 384,
320, 323, 338 449, 460–462, 469, 509
Hyperdata, 11, 94, 170–171, 181–183, 188,
190, 192–194
D Hypermedia, 2, 3, 5–7, 10, 11, 13, 29, 32,
Design Constraints, 2, 8 33, 37, 42, 45, 49, 61, 65, 67–70, 77,
Discovery, 5, 16, 40, 61, 63, 72, 94, 97, 140, 93–115, 140, 161, 164, 166, 170–171,
212, 222–224, 226, 230, 234, 298, 305, 179–183, 189, 194, 199–218, 261, 262,
316, 321, 364, 382, 389–394, 396–398, 305, 347–350, 354, 364, 408, 426, 434,
402, 404, 409, 411, 426, 436, 468–470, 439, 452, 463, 475–478, 480, 508
474, 481, 483, 492, 496, 498–502, 504 Hypermedia as the engine of application state
Distributed atomic transactions, 17, 507–522 (HATEOAS), 32, 33, 37, 45–46, 48,
Distributed programming environment, 341 50–52, 180, 347, 350, 354, 408, 412,
Django Framework, 127–132 463
Domain model, 13, 190, 260–262, 264–269, Hypertext markup language (HTML), 1, 36,
271, 273, 275, 277, 278, 347 70, 96, 143, 168, 242, 305, 360, 387,
427, 434, 463, 474
E
Electronic product code information service I
(EPCIS), 14, 360–363, 365–376, 378 Idempotent, 5, 30, 51, 85, 98, 101, 103,
Evaluation, 213–217, 372–373, 408 106–108, 114, 155, 165, 172, 174, 184,
Event, 14, 36, 140 189, 192, 194, 351, 364, 411, 507, 510,
514, 516, 517
Influence diagram, 9, 26–31, 33
F Information system, 2, 13, 14, 95, 279–299,
Functional observer REST (FOREST), 11, 304, 317, 361, 364–365, 370–374, 378,
161–194 456
G J
Gleaning resource description from dialect of Javascript object notation (JSON), 44, 48, 49,
languages (GRDDL), 467, 468, 470, 97, 104, 119, 131, 168–170, 172, 176,
483 190, 192, 193, 204, 206, 208, 229, 231,
Grid, 13, 319, 327 243, 247, 253, 255, 267, 277, 347–349,
Guard clauses, 53, 122, 123, 126, 131, 132 364, 368, 374, 389, 392–395, 398, 425,
428–432, 443
JAX-RS, 48, 50, 297, 373–375
H JBoss REST-*, 520
HATEOAS. See Hypermedia as the engine of Jersey, 48, 50, 51, 297, 369, 374–375, 450
application state (HATEOAS) JSON. See Javascript object notation (JSON)
Heuristic decision, 520
Heuristic exception, 517–519
Heuristic rollback, 518 L
hRESTS, 393–395, 474, 475, 481–492, 498, Legacy data, 304–308, 316, 317
499, 502–504 Legacy system, 51, 340, 341, 350, 351, 353
HTML. See Hypertext markup language Link relation types, 70
(HTML) Lookup, 386, 387, 409–412, 414
Index 527
State machine, 11, 65–67, 88, 118, 121–127, User interface, 7, 12, 29, 32, 95, 199–209,
131, 132, 134, 178, 512 211–218, 241, 250, 255, 256, 304, 306,
State transitions, 3, 66, 69, 96, 97, 115, 353, 321, 325, 335, 345, 390, 392, 394, 398,
513 447, 450, 453, 497, 502
W
T
Web-centric environment, 14
Testing, 47, 48, 245, 329–335, 343
Web of things (WOT), 9, 15, 364, 365,
TIP and WS-AT, 520
382–384, 388–390, 393, 395, 397–399
Toolkit, 12, 202, 204–207, 209, 211, 218,
Web services description language (WSDL), 5,
256, 353, 363, 375, 378, 453,
6, 36–40, 325, 383, 474, 480–483, 499,
454
504, 505
Transactional context, 513
Workflow, 14, 51, 191, 233, 284–285, 294,
Try-Cancel/Confirm (TCC) pattern, 17, 512,
320–322, 324–336, 338
522
WOT. See Web of things (WOT)
Two-phase commit protocol (2PC), 517
WS-*, 2, 4, 5, 8–10, 14, 39, 360, 361, 363, 365,
367, 369–373, 375, 378, 517, 520–522
WSDL. See Web services description language
U (WSDL)
UML class diagram, 11, 118, 119, 121, 134, WSMO-Lite, 474, 475, 482, 492–496, 499,
260, 261 505
Uniform interface, 3, 5–7, 11, 22, 23, 29, 31,
39, 62, 64, 67, 68, 118, 121, 134, 156,
167, 170, 217, 256, 259, 260, 276, 282, X
343, 347–351, 363, 364, 368, 374, 405, XA protocol, 513
411, 417, 433, 507, 509, 522 XForms, 75, 77, 89, 90