Introduction to RESTful
Web Services
Extend or add functionality into your applications with RESTful Web services.
MAX BONBHEL
JAVA IN ACTION
This article, the first of a three- part series, demonstrates
how to create a Java Platform,
Enterprise Edition (Java EE) application integrating Representational
State Transfer (REST) Web services. I will use the NetBeans 6. 9. 1
IDE and Java EE 6 to create the
application and Oracle GlassFish
Server 3. 1 to deploy it.
Part 2 (coming in the next issue) covers managing the answers
sent by a Web service using the
JavaScript Object Notation (JSON)
framework, while Part 3 focuses on
the integration of Java API for XML
Web Services (JAX-WS). These
articles highlight methods for
increasing application agility.
with other systems via Hyper Text
Transfer Protocol (HTTP) using
Extensible Markup Language
(XML). Web services allow you to
mask the complexity of each application included in the exchange
and achieve complex operation.
Web services are more than the
sum of the technologies used to
deploy an application. They are a
method for carving out services
from business functionalities that
are then exposed to be consumed
by client applications.
ers and the consumers of the
services. And RESTful Web
services provide support for
a variety of message formats
(XML, JSON, HTML, and more).
■ ■ RESTful Web services are easy
to integrate into existing applications in order to extend or
add new functionality.
REST is just an architectural
style, not a technology. That is
why there is a specification, JSR-
311, to describe how REST should
be implemented in Java. There
have been several implementations of this standard. Jersey is the
official reference implementation
and the one that is most widely
used in development and production. Jersey is open source and
backed by Oracle.
However, REST might have
some limitations when it comes
to “big” Web services. This will be
discussed in Part 3 of the series.
scribed in this article:
■ ■ NetBeans IDE. Download here.
■ ■ Jersey (included in NetBeans):
It is the open source, produc-
tion-quality reference imple-
mentation for a Java EE speci-
fication (JAX-RS JSR-311) for
building RESTful Web services.
Note: This article was tested using
NetBeans IDE 6. 9. 1; as of this writing, the latest version is NetBeans
IDE 7.0.
ABOUT US
What Are Web Services?
Web services provide a standard
means of interoperating among
software applications that run on
a variety of platforms or frameworks. In other words, Web services are the best and standard
way to extend your application
in order to make it interoperable
Why RESTful Web Services?
Java EE 6 provides natively all
mechanisms for REST via the “Java
API for RESTful Web Services”
(JAX-RS), JSR-311. There are many
good reasons to choose REST to
add the Web services into your
system. Here are some examples:
■ ■ The most important reason is
that RESTful Web services are
easy to learn, easy to build, and
easy to deploy.
■ ■ REST provides a uniform interface between the produc-
Real-Life Application
In this practical section, we will
build a real-life application step
by step so that you can learn
quickly the basics of the RESTful
Web services.
The application is an online
auction place (like eBay). Sellers
post their items in listings, and
buyers bid on the items. A seller
can post one or many items, and
a buyer can bid on one or many
items. To simplify, we will consider the following entities: Seller,
Item, and Bid.
You can also download all the
blog
PHOTOGRAPH BY
ALLEN MCINNIS/GETTY IMAGES
Prerequisites
The following software was used
to develop the application de-