All Projects → pippo-java → Pippo

pippo-java / Pippo

Licence: apache-2.0
Micro Java Web Framework

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Pippo

Swoft
🚀 PHP Microservice Full Coroutine Framework
Stars: ✭ 5,420 (+629.48%)
Mutual labels:  microservice
Microservices Event Sourcing
Microservices Event Sourcing 是一个微服务架构的在线购物网站,使用Spring Boot、Spring Cloud、Spring Reactor、OAuth2、CQRS 构建,实现了基于Event Sourcing的最终一致性,提供了构建端到端微服务的最佳实践
Stars: ✭ 657 (-11.57%)
Mutual labels:  microservice
Istio
Connect, secure, control, and observe services.
Stars: ✭ 28,970 (+3799.06%)
Mutual labels:  microservice
Avatar
💎 Beautiful avatars as a microservice
Stars: ✭ 623 (-16.15%)
Mutual labels:  microservice
Brpc Java
Java implementation for Baidu RPC, multi-protocol & high performance RPC.
Stars: ✭ 647 (-12.92%)
Mutual labels:  microservice
Vertx Blueprint Microservice
Vert.x Blueprint Project - Micro-Shop microservice application
Stars: ✭ 663 (-10.77%)
Mutual labels:  microservice
Flatend
Quickly build microservices using p2p networking in NodeJS/Go.
Stars: ✭ 600 (-19.25%)
Mutual labels:  microservice
Zend Expressive
PSR-15 middleware in minutes!
Stars: ✭ 740 (-0.4%)
Mutual labels:  microservice
Uavstack
UAVStack Open Source All in One Repository
Stars: ✭ 648 (-12.79%)
Mutual labels:  microservice
Servicecomb Mesher
A high performance service mesh implementation written in go
Stars: ✭ 676 (-9.02%)
Mutual labels:  microservice
Problem Spring Web
A library for handling Problems in Spring Web MVC
Stars: ✭ 636 (-14.4%)
Mutual labels:  microservice
Micromono
Write microservices in monolithic style
Stars: ✭ 644 (-13.32%)
Mutual labels:  microservice
Tseer
A high available service discovery & registration & fault-tolerance framework
Stars: ✭ 665 (-10.5%)
Mutual labels:  microservice
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (-16.42%)
Mutual labels:  microservice
Akka Http Microservice
Example of http (micro)service in Scala & akka-http
Stars: ✭ 701 (-5.65%)
Mutual labels:  microservice
Gubernator
High Performance Rate Limiting MicroService and Library
Stars: ✭ 609 (-18.03%)
Mutual labels:  microservice
Restheart
RESTHeart - The REST API for MongoDB
Stars: ✭ 659 (-11.31%)
Mutual labels:  microservice
Micro Analytics Cli
Public analytics as a Node.js microservice. No sysadmin experience required! 📈
Stars: ✭ 743 (+0%)
Mutual labels:  microservice
Qbit
The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
Stars: ✭ 702 (-5.52%)
Mutual labels:  microservice
Microservices Reference Implementation
A reference implementation demonstrating microservices architecture and best practices for Microsoft Azure
Stars: ✭ 671 (-9.69%)
Mutual labels:  microservice

Micro Java Web Framework

Join the chat at https://gitter.im/decebals/pippo 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.
The size of pippo-core is only 140 KB and the size of pippo-controller (optional) is only 45 KB.

Sample code

1. Routes approach

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 -> {
            Contact contact = createContact();
            routeContext.xml().negotiateContentType().send(contact);
        });

        // send a template with name "hello" 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-jetty</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

2. Controllers approach

Define controller(s):

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

    private ContactService contactService;

    public ContactsController() {
        contactService = new InMemoryContactService();
    }

    @GET
    @Named("index")
//    @Produces(Produces.HTML)
    @Metered
    @Logging
    public void index() {
        // inject "user" attribute in session
        getRouteContext().setSession("user", "decebal");

        // send a template with name "contacts" as response
        getResponse()
            .bind("contacts", contactService.getContacts())
            .render("contacts");
    }

    @GET("/uriFor/{id: [0-9]+}")
    @Named("uriFor")
    @Produces(Produces.TEXT)
    @Timed
    public String uriFor(@Param int id, @Header String host, @Session String user) {
        System.out.println("id = " + id);
        System.out.println("host = " + host);
        System.out.println("user = " + user);

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("id", id);

        String uri = getApplication().getRouter().uriFor("api.get", parameters);

        return "id = " + id + "; uri = " + uri;
    }

    @GET("/api")
    @Named("api.getAll")
    @Produces(Produces.JSON)
    @NoCache
    public List<Contact> getAll() {
        return contactService.getContacts();
    }

    @GET("/api/{id: [0-9]+}")
    @Named("api.get")
    @Produces(Produces.JSON)
    public Contact get(@Param int id) {
        return contactService.getContact(id);
    }

}
@Path("/files")
public class FilesController extends Controller {

    @GET
    public void index() {
        // send a template with name "files" as response
        getRouteContext().render("files");
    }

    @GET("/download")
    public File download() {
        // send a file as response
        return new File("pom.xml");
    }

    @POST("/upload")
    @Produces(Produces.TEXT)
    public String upload(FileItem file) {
        // send a text (the info about uploaded file) as response
//        return file.toString();
        return new StringBuilder()
            .append(file.getName()).append("\n")
            .append(file.getSubmittedFileName()).append("\n")
            .append(file.getSize()).append("\n")
            .append(file.getContentType())
            .toString();
    }

}

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

        addControllers(FilesController.class);
    }

}

Don't forget that the Controller concept is included in pippo-controller module so you must add this module as dependency in your project.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].