Code Monkey home page Code Monkey logo

pippo's Introduction

Micro Java Web Framework

Travis CI Build Status Coverage Status Maven Central

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.

Sample code

First we must create an Application and add some routes:

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

where Contact is a simple POJO:

public class Contact  {

    private int id;
    private String name;
    private String phone;
    private String address;
    
    // getters and setters

}

The second step is to choose your favorite server, template engine and content type engine.
For example, I will choose Jetty as server, Freemarker as template engine, Jackson as JSON engine and JAXB as XML engine.
My Maven pom.xml looks like:

<dependency>
    <groupId>ro.pippo</groupId>
    <artifactId>pippo-core</artifactId>
    <version>${pippo.version}</version>
</dependency>

<dependency>
    <groupId>ro.pippo</groupId>
    <artifactId>pippo-freemarker</artifactId>
    <version>${pippo.version}</version>
</dependency>

<dependency>
    <groupId>ro.pippo</groupId>
    <artifactId>pippo-jackson</artifactId>
    <version>${pippo.version}</version>
</dependency>

The last step it's to start Pippo with your application as parameter:

public class BasicDemo {

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

}

Pippo launches the embedded web server (found in your classpath) and makes the application available on port 8338 (default value). Open your internet browser and check the routes declared in Application:

  • http://localhost:8338
  • http://localhost:8338/file
  • http://localhost:8338/json
  • http://localhost:8338/xml
  • http://localhost:8338/negotiate
  • http://localhost:8338/template

Documentation

Documentation is available on pippo.ro

Demo

Demo applications are available on pippo-demo
For a real life application built with Pippo please look at Web Accounting - Pippo Demo

pippo's People

Contributors

balamaci avatar danjee avatar decebals avatar gitblit avatar gustavogalvan avatar lmicra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.