Webbit-REST is a small Sinatra-inspired API for the Webbit web server. It is based on RFC 6570 and the excellent wo-furi library.
WebServer webServer = new NettyWebServer(9991);
Rest rest = new Rest(webServer);
rest.GET("/people/{name}/pets/{petName}", new HttpHandler() {
@Override
public void handleHttpRequest(HttpRequest req, HttpResponse res, HttpControl ctl) {
String name = Rest.param(req, "name");
String petName = Rest.param(req, "petName");
res.content(String.format("Name: %s\nPet: %s\n", name, petName)).end();
}
});
webServer.start().get();
System.out.println("Try this: curl -i localhost:9991/people/Mickey/pets/Pluto");
rest.GET("/people/{name}/animals/{petName}", new HttpHandler() {
@Override
public void handleHttpRequest(HttpRequest req, HttpResponse res, HttpControl ctl) {
Rest.redirect(res, "/people/{name}/pets/{petName}",
"name", param(req, "name"),
"petName", param(req, "petName")
);
}
});
<dependency>
<groupId>org.webbitserver</groupId>
<artifactId>webbit-rest</artifactId>
<version>0.2.0</version>
</dependency>