Skip to content

webbit/webbit-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webbit-REST

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.

Sample usage:

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");

Redirecting:

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")
        );
    }
});

Installation

Maven

<dependency>
    <groupId>org.webbitserver</groupId>
    <artifactId>webbit-rest</artifactId>
    <version>0.2.0</version>
</dependency>

Not Maven

https://oss.sonatype.org/content/repositories/releases/org/webbitserver/webbit-rest/0.2.0/webbit-rest-0.2.0.jar