Author:Gao Ang Representational Central to the The most useful The following HTTP CRUD POST Create, GET Read PUT Create, DELETE Delete NetBeans 6.x supports the rapid development of RESTful web services using Here are some highlights of RESTful Web Services in NetBeans: First, let’s create Based on our RestDemo Singleton pattern We should specify Resource Now, we get the Besides, we get Then we use Glassfish Right click on the RestDemo project node and select “Test RESTful Web In the web explorer, we could see a link for the web The result will show up in the Http monitor. We get the http://www.netbeans.org/community/magazine/html/04/restfulws.html http://www.testearly.com/ http://zh.wikipedia.org/w/index.php?title=REST&variant=zh-cn
state transfer (REST) is a style of software architecture for distributed
hypermedia systems. The terms “representational state transfer” and “REST” were
introduced in
the doctoral dissertation of Roy Fielding, who is one of the principal authors
of the Hypertext Transfer Protocol(HTTP) specification.
RESTful architecture style is the concept of resources identified by universal
resource identifiers (URIs). Resources can be manipulated using a standard
interface, such as HTTP, and information is exchanged using representations of
these resources. REST is not strictly only a method of building web services. Building
web services using the RESTful approach is emerging as a popular alternative to
using SOAP-based technologies for deploying services on the Internet, due to
its lightweight nature.
HTTP methods are POST, GET, PUT and DELETE. These
are often compared with the CREATE, READ, UPDATE, DELETE (CRUD) operations
associated with database technologies.
table associates several common HTTP verbs with similar database operations,
however the meaning of the HTTP verbs do not correspond directly with a single
database operation. For example, an HTTP PUT is used to set the value of a
resource and may result in either a creation or replacement as needed.
Update, Delete
Overwrite/Replace
REST emphasis on the diversity of resources, we could understand the
meaning of the operation when we see the URL of the link. For example, a REST
application might define the following resources:
For Ruby on Rails, RESTful web services are the default style in the scaffold
generation of the framework. Now, with Netbeans, we could create a RESTful web
services application in Java from scratch easily.
JSR-311 (Java API for RESTful Web Services – JAX-RS), the reference
implementation for JAX-RS. NetBeans IDE supports building and testing services,
as well as creating client applications that access these services, and
generating code for invoking web services (both RESTful and SOAP-based).
RESTful web services from Java Persistence API entity classes and patterns.
generation for invoking web services such as Google Maps, Yahoo News Search by
drag-and-dropping components from the RESTful component palette.
client stubs from RESTful web services for building client applications.
generation for testing RESTful web services.
easy navigation of RESTful web service implementation classes in project.
To follow this tutorial, we need the following software and resources.
use the NetBeans 6.1 version)
Application Server
Besides, we need
the RESTful web services plugin to implement our demo code. Fortunately, we get
this plugin installed by default if we choose the NetBeans web development
edition.
![]()

a new project in Netbeans. We will select Web Application in Web Categories and
click Next.
![]()

In the next step, we name the project as “RestDemo”. Leave the rest as default and
step into the next view:

![]()
GlassFish is an application server project by Sun Microsystems for the Java
Enterprise Edition (Java EE) platform. We use GlassFish V2 as the server of our
web services, and RestDemo as the context path and then click Finish.
![]()

project, we are gonna create Web Resource for the web application.
![]()
is a design pattern that is used to restrict instantiation of a class to one
object. We use Singleton Pattern to create a simple Java Class for our web
resource like this:
![]()

Name and other required for the Resource class and finish this procedure. We
use text/html MIME Type to display the response in HTML format.

![]()
generated HTTP methods and the tree view of our project looks like:
![]()
the generated source code in DemoResource.java, before we start up the web
server. Let’s add some code to return sample HTML message in getHtml method, which
looks like:
![]()
to test the RESTful Web Services, Glassfish configuration looks like:
![]()

Services”option to start server. GlassFish V2 application server will start and
jump to our deployed web application.
![]()
service that we just created, choose the GET(text/html) method to test our
service.
html text in the received parameter like this:

Besides, we could also generate RESTful web services from database and generate
CRUD operation in RESTful style for the database record with the help of powerful
Netbeans IDE.
Reference:
http://en.wikipedia.org/wiki/REST