Skip to content
Pierre-Yves Gibello edited this page Jun 3, 2020 · 10 revisions

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:

The developer may extend the 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