Saturday, January 07, 2006

Restlet - A Java Framework for REST

Jerome Louvel, a developer based in Levallois-Perret, France, has established a project known as the Restlet project to create a REST framework on top of the Java Servlet API. In his tutorial available from the official webpage, a bit of its server-side programming model is shown with a "Hello World!" example.
 // Creating a minimal handler returning "Hello World"
UniformInterface handler = new UniformInterface() {
public void handle(UniformCall call) {
call.setOutput(new StringRepresentation("Hello World!",
MediaTypes.TEXT_PLAIN));
}
};

// Create the HTTP server and listen on port 8182
new JettyServer("My Web server", 8182, handler).start();

If you run this code and launch your server, you can open a Web browser and hit the http://localhost:8182. Actually, any URI will work, try also http://localhost:8182/test/tutorial. This handler is very primitive and only takes advantage of the pure REST part of the Restlet framework. Later in the tutorial, we can see how to take advantage of the Restlets in order to facilitate this processing.

No comments: