Saturday, June 15, 2013

JAX-RS 2 Starter Project

I've been experimenting with new features in JAX-RS 2, The Java API for RESTful Web Services. In doing so, I have created a jaxrs2-starter-kit project to help others quickly get up and running. It is available for download at GitHub by issuing the following command:

git clone https://github.com/jchart-github/jaxrs2-starter-kit.git

It contains sample client and server that is easily built and run using Maven.

The project demonstrates:
  • The new Client API
  • Request/Response
  • The Invocation Object and the Command Pattern
  • Build-in Entity Resolvers for Object Unmarshalling
  • Server Resource
  • Server Filter
  • Spring Integration
  • Content Negotiation with using default Entity Resolvers 

Browse the jaxrs2-starter-kit

The starter kits implements a /books resource.
It uses the following rules in its RESTFul implementation:

For collections

Resource /books
@POST create a new book
@GET list all books
@PUT bulk update books
@DELETE delete all books


For single resources

Resources /books/{id}
@POST Error
@GET return a book
@PUT if exists, update book; if not ERROR
@DELETE delete a book



2 comments:

  1. Thanks Paul. That was helpful.

    Just one question, on writing those data object, like Book and Books.
    Does that just have to be JavaBeans or we do some thing with MessageBodyReader/MessageBodyWriter or Jettison or Jackson??

    ReplyDelete
  2. Bipin,

    The data objects are POJOs. They get automatically serialized/de-serialized to JSON by the Jackson providers. The nice thing is that for the simple case, one needs not to do anything to configure it. Jackson contains the @Provider annotation so it gets automatically discovered. https://github.com/FasterXML/jackson-jaxrs-providers/blob/master/json/src/main/java/com/fasterxml/jackson/jaxrs/json/JacksonJsonProvider.java

    I'm glad it was helpful.

    ReplyDelete