Web services that follow Representational State Transfer principles are called REST web services. In REST, resources are identified by URIs and clients communicate using standard set of methods.
Principles of REST
- Resources are identified by URIs. For example:
http://example.com/widgets/bar
http://example.com/employees/foo
- Standard set of methods:
GET – Read
POST – Update or create without a known id
PUT – Update or create with a known id
DELET – Remove - Link things together. Once client knows the entry point, it should be able to navigate to all other parts of the application.
- Multiple representations
Offer data in multiple formats (XML, JSON, HTML). Goal is to maximize reach. - Content negotiation using Accept header or URI. For example:
Header based negotiation:
GET /foo
Accept: application/json
URI-based: GET /foo.json - Stateless communications
Everything required to process a request should be contained in the request. Avoid using sessions because they are less scalable and cannot be bookmarked.
JAX-RS 1.1 Overview
JAX-RS is a specification defined by JSR-311 in the Java Community Process. Current available version is 1.1. Some of the key features provided by JAX-RS include:
- POJO based resource API (Server side)
- HTTP Centric
- Container independent
- Inclusion in Java EE but without dependency
- Annotation driven. For example:
@Path
@Produces/Consumes
@HEAD/PathParam/QueryParam
@GET/POST/PUT/DELETE - Data format/media types – XML, JSON, (X)HTML
- Accept HTTP header and URI-based content negotiation
JAX-RS 2.0 is under development and will provide more features including:
* Low level client API using builder pattern
* Hypermedia
* Bean validation for form or query parameters
* Filters/Handlers
* Server-side asynchronous request processing
* Server-side content negotiation
Jersey Overview
Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services.
- Multiple container support
- Resource configuration
* Server filters
* Resource filters
* Plugable component providers
* Pluggable dispatchers
* Pluggable JAX-RS providers
* Resource Injection - Client API with client configuration
- WADL support for representation of resources
- JSON with JAXB binding
- Spring integration
- MIME multipart API
- Atom