gibello edited this page Jan 30, 2012 · 9 revisions
Clone this wiki locally

ICAr REST/JSON framework (servlet-based)

This REST framework is made of... just 4 classes (+ a basic sample). There are 3 more classes to implement a lightweight JSON parser. It allows to easily provide web resources in CRUD mode, as usual in REST style.

It aims at being mixed in your own code (although you may also include it as any other 3rd-party tool): feel free to take (parts of) the code, rename packages/classes, add new functionalities, fix whatever you consider a bug... and mix the result in your own project.

To make it possible, this code is covered by a BSD license.

REST quick start

This project is itself a web application: when deployed on a servlet container, the sample described below should be up and running (links are provided). So, try to export it as a .war package, deploy it on your app server, and open the webapp in a web browser (a doc page should be displayed).

Then have a look at the rest.sample package. There is a servlet that registers 2 resources:

  • The 1st one, "HelloWorldResource", displays a message (and is registered as "/demo/hello" by the servlet).
  • The 2nd one, "DisplayNameResource", expects a HTTP parameter called "name" to display a greeting message (and is registered as "/demo/greetings" by the servlet).

Then, the servlet is declared in WEB-INF/web.xml (with url-pattern set to "/demo/*"), and that's all.

More details: see developer documentation

JSON quick start

The framework provides a (quite basic) JSON parser, that works in "push" mode (like SAX for XML). Package: cades.icar.rest.json.

The developer may extend the cades.icar.rest.json.DefaultHandler class, to receive parsing events (eg. the startObject() method will be invoked at the beginning of a JSON object, the key(String key) and simpleValue(String val) methods upon each occurrence of a "name/simple value" pair, etc...)

The DefaultHandler class implements all parsing methods, but does nothing: you just have to override methods that correspond to parsing events you wish to intercept.

More details: see developer documentation


This framework was first developed in 2011 for the needs of the CADES project (a software suite for design and optimization of physical systems), on behalf of PetalsLink (EBM Websourcing) company. It was financed by public funding from a french research project (ANR Siminthec).