Fork me on GitHub
 ____  ____  ____  ____  _____
(  _ \(_  _)(  _ \(  _ \(  _  )
 ) __/ _)(_  ) __/ ) __/ )(_)( 
(__)  (____)(__)  (__)  (_____)

It's an open source (Apache License) micro web framework in Java, with minimal dependencies and a quick learning curve.
The goal of this project is to create a micro web framework in Java that should be easy to use and hack.
Pippo can be used in small and medium applications and also in applications based on micro services architecture.
We believe in simplicity and we will try to develop this framework with these words in mind.

The core is small (around 140 KB) and we intend to keep it as small/simple as possible and to push new functionalities in pippo modules and third-party repositories/modules.
You are not forced to use a specific template engine or an embedded web server. Furthermore you have multiple out of the box options (see Templates and Server).

Also, Pippo comes with a very small footprint that makes it excellent for embedded devices (Raspberry Pi for example).

The framework is based on Java Servlet 3.0 and requires Java 8.


Talk is cheap. Show me the code.

1.1 Routes approach

Add some routes in your application:

public class BasicApplication extends Application {

    @Override
    protected void onInit() {
        // send 'Hello World' as response
        GET("/", routeContext -> routeContext.send("Hello World"));

        // send a file as response
        GET("/file", routeContext -> routeContext.send(new File("pom.xml"));

        // send a json as response
        GET("/json", routeContext -> {
            Contact contact = createContact();
            routeContext.json().send(contact);
        });

        // send xml as response
        GET("/xml", routeContext -> {
            Contact contact = createContact();
            routeContext.xml().send(contact);
        });

        // send an object and negotiate the Response content-type, default to XML
        GET("/negotiate", routeContext -> {
            Contact contact = createContact();
            routeContext.xml().negotiateContentType().send(contact);
        });

        // send a template as response
        GET("/template", routeContext -> {
            routeContext.setLocal("greeting", "Hello");
            routeContext.render("hello");        
        });
    }

    private Contact createContact() {
        return new Contact()
            .setId(12345)
            .setName("John")
            .setPhone("0733434435")
            .setAddress("Sunflower Street, No. 6"); 
    }

}

1.2 Controllers approach

Define controller(s):

@Path("/contacts")
public class ContactsController extends Controller {

    @GET("/?")
    public void index() {
        List<Contact> contacts = contactService.getContacts();
        getResponse().bind("contacts", contacts).render("contacts");
    }

    @GET("/{id: [0-9]+}")
    public void getContact(@Param int id) {
        Contact contact = contactService.getContact(id);
        getResponse().bind("contact", contact).render(contact);
    }

    @GET("/text")
    @Named("text")
    @Produces(Produces.TEXT)
    @NoCache
    public void complex(@Param int id, @Param String action, @Header String host, @Session String user) {
        // do something
    }

}

Add controller(s) in your application:

public class BasicApplication extends ControllerApplication {

    @Override
    protected void onInit() {
        addControllers(ContactsController.class); // one instance for EACH request
        // OR
        addControllers(new ContactsController()); // one instance for ALL requests        
    }

}

2. Start your application

public class BasicDemo {

    public static void main(String[] args) {
        Pippo pippo = new Pippo(new BasicApplication());
        pippo.start();
    }

}

See Getting started section for some basic information.