RESTing with Jongo

For the last few weekends and as part of a week of holidays where I had to stay at home taking care of my convalescent wife I started a project called Jongo which is a RESTful interface for JDBC that allows any application to directly access a RDBMS using the different HTTP methods. The idea came from working with CouchDB's RESTful JSON API but using the ability of Java's JDBC to be database independent.

So what does all this gibberish means? To put it in a simple way, you can, for example, develop JavaScript only applications with a database back-end without doing any server side development.

For example, say you have a table with some users and you want to GET the first one:

$ curl -X GET "http://localhost:8080/jongo/user/1"
{"success":true, "count":1, "resource":"user", "response":[{"birthday":"null","credit":"45.00","lastupdate":"null","name":"foo user","age":30,"id":4}]}

If you want to INSERT a new user, you would POST it with:

$curl -X POST -d '{"name":"foo user", "age":30, "credit":45.0}' "http://localhost:8080/jongo/user"

Since the default format is JSON, we provide a JSON object or an array of JSON objects. This will be formatted to native SQL values and inserted in the database as new user.

To UPDATE an user, you would perform a PUT request with the new values:

$ curl -X PUT -d  '{"name":"user change", "age":34}' "http://localhost:8080/jongo/user/4"

And finally, the DELETE:

$ curl -X DELETE "http://localhost:8080/jongo/user/4"

I hope this explains a little what a RESTful webservice is and how Jongo helps on publishing your RDBMS without any server-side development.