REST is an architectural style. HTTP is a protocol which contains the set of REST architectural constraints.

REST fundamentals

Everything in REST is considered as a resource.

Every resource is identified by an URI.

Uses uniform interfaces. Resources are handled using POST, GET, PUT, DELETE operations which are similar to Create, Read, update and Delete(CRUD) operations.

Be stateless. Every request is an independent request. Each request from client to server must contain all the information necessary to understand the request.

Communications are done via representations. E.g. XML, JSON

RESTful Web Services

RESTful Web Services have embraced by large service providers across the web as an alternative to SOAP based Web Services due to its simplicity. This post will demonstrate how to create a RESTful Web Service and client using Jersey framework which extends JAX-RS API. Examples are done using Eclipse IDE and Java SE 6.

Creating RESTful Web Service

In Eclipse, create a new dynamic web project called “RESTfulWS”

Download Jersey zip bundle from here. Jersey version used in these examples is 1.17.1. Once you unzip it you’ll have a directory called “jersey-archive-1.17.1″. Inside it find the lib directory. Copy following jars from there and paste them inside WEB-INF -> lib folder in your project. Once you’ve done that, add those jars to your project build path as well.

asm-3.1.jar

jersey-client-1.17.1.jar

jersey-core-1.17.1.jar

jersey-server-1.17.1.jar

jersey-servlet-1.17.1.jar

jsr311-api-1.1.1.jar

In your project, inside Java Resources -> src create a new package called “com.eviac.blog.restws”. Inside it create a new java class called “UserInfo”. Also include the given web.xml file inside WEB-INF folder.

Newsletter

Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

Email address:

Join Us

With 1,043,221 monthly unique visitors and over 500 authors we are placed among the top Java related sites around. Constantly being on the lookout for partners; we encourage you to join us. So If you have a blog with unique and interesting content then you should check out our JCG partners program. You can also be a guest writer for Java Code Geeks and hone your writing skills!