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 "xxxxx"
- Download Jersey zip bundle . 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
- write one Java Class. ...
- Define Jersey Servlet dispatcher. ...
- Run your rest service.