RESTful Web Services

Implementing REST resources with JAX-RS

REST stands for Representational State Transfer and is an architectural style for distributed systems. In REST, data and functionality are represented as 'resources' which can be accessed using a Uniform Resource Identifier (URI/URL) and acted upon using a simple set of well-defined actions, namely the HTTP verbs GET, POST, PUT and DELETE.

JAX-RS is the Java API for RESTful web services. A RESTful web service in JAX-RS is a plain old Java object (POJO) which has been annotated with JAX-RS annotations. These annotations define how the resource is to be contacted: the URL segment the resource services, which HTTP method it responds to, what parameters it accepts and what it returns as shown in the example below.

Why RESTful Services?

  • Easy to implement: With JAX-RS, RESTful services are easy to create and deploy. With a few annotations, you are up and running.

  • Loose coupling: Any client that wishes to utilize a RESTful service only requires three pieces of information about it - the URL, the parameters and the format of the response. Once these are established, the client and service can be implemented more or less independently.

  • Easy to integrate: RESTful services are easily consumed by a variety of clients, including modern JavaScript frameworks like Ext JS.