Alex headshot

AlBlue’s Blog

Macs, Modularity and More

Restlet

2010, java

Restlet is a massively under-used library for serving REST based requests over the web. It's fully OSGi compatible (unlike Jersey, which uses a bunch of com.sun stuff under the covers) and has recently released version 2.0.

I recently posted a cryptic tweet in response to @Vogella's article on REST with Jersey, since Jersey has repeatedly failed in an OSGi runtime like environment. Using Restlet is a much smarter move if you want to serve REST based requests.

Here's the Hello World of Restlet:

import org.restlet.*;
import org.restlet.data.*;
import org.restlet.resource.*;
public class Test {  
  public static void main(String[] args) throws Exception { 
    int port = 8080; 
    new Server(Protocol.HTTP, port, HelloResource.class).start();  
  }
  public static class HelloResource extends ServerResource {
    @Get 
    public String helloWorld() { 
      return "Hello World";
    }
  }
}

Run that, with restlet-2.0.1.jar on your classpath, and then point your browser to http://localhost:8080.

There's a lot more documentation in the Restlet tutorial if you want to know more.