This article explains how to develop RESTful web services in Java with the JAX-RS reference implementation Jersey.
In this article Eclipse (Helios), Java 1.6, GlassFish 3.0.1 and JAX-RS 1.1. (Jersey 1.5) is used.
Introduction
- JAX-RS stands for Java API for XML RESTful Services
- A RESTFul webservices is based on the HTTP methods
- In a REST based architecture everything is a resource.
- It typically defines the base URI for the services, the MIME-types its supports (XML, Text, JSON, user-defined,..) and the set of operations (POST, GET, PUT, DELETE) which are supported.
- JAX-RS supports the creation of XML and JSON via JAXB.
- JAXB stands for Java Architecture for XML Binding
- (JAXB) is a Java standard that defines how Java objects are converted to/from XML
- @XmlRootElement Define the root element for a XML tree
CRUD/HTTP mapping | |
Application task | HTTP command |
Create | POST |
Read | GET |
Update | PUT |
Delete | DELETE |
Example
1) Create Dynamic Web Project
2) To start working with Jersy you need to put the needed JARs in the lib folder, as we are using GlassFish we don't need this step as it is already there
If it's not there, you can install it on GlassFish
References
http://jonas.ow2.org/JONAS_5_2_0_M4/doc/doc-en/html/howto_use_jaxrs.html
http://www.myeclipseide.com/documentation/quickstarts/webservices_rest/
http://www.vogella.de/articles/REST/article.html
https://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with
http://docs.oracle.com/cd/E19776-01/820-4867/ggnzk/index.html