Filter - > ANY  ,  GET -> GET ,POST -> POST 极致精简

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.1 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 {@Overrideprotected void onInit() {// send 'Hello World' as responseGET("/", routeContext -> routeContext.send("Hello World"));// send a file as responseGET("/file", routeContext -> routeContext.send(new File("pom.xml")));// send a json as responseGET("/json", routeContext -> {Contact contact = createContact();routeContext.json().send(contact);});// send xml as responseGET("/xml", routeContext -> {Contact contact = createContact();routeContext.xml().send(contact);});// send an object and negotiate the Response content-type, default to XMLGET("/negotiate", routeContext -> {Contact contact = createContact();routeContext.xml().negotiateContentType().send(contact);});// send a template with name "hello" as responseGET("/template", routeContext -> {routeContext.setLocal("greeting", "Hello"); // template's model/contextrouteContext.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")
@Logging
public class ContactsController extends Controller {private ContactService contactService;public ContactsController() {contactService = new InMemoryContactService();}@GET@Named("index")
//    @Produces(Produces.HTML)@Metered@Loggingpublic void index() {// inject "user" attribute in sessiongetRouteContext().setSession("user", "decebal");// send a template with name "contacts" as responsegetResponse().bind("contacts", contactService.getContacts()).render("contacts");}@GET("/uriFor/{id: [0-9]+}")@Named("uriFor")@Produces(Produces.TEXT)@Timedpublic 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)@NoCachepublic 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 {@GETpublic void index() {// send a template with name "files" as responsegetRouteContext().render("files");}@GET("/download")public File download() {// send a file as responsereturn 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 {@Overrideprotected void onInit() {addControllers(ContactsController.class); // one instance for EACH request// ORaddControllers(new ContactsController()); // one instance for ALL requestsaddControllers(FilesController.class);}}

2. Start your application

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

原文地址:http://www.pippo.ro/

Pippo java微服务,轻量级web开发框架,原来Filter还能这么玩相关推荐

  1. NutzWk 5.2.4 发布,Java 微服务分布式开发框架

    开发四年只会写业务代码,分布式高并发都不会还做程序员?   NutzWk 5.2.4 更新内容: 修复Vue版管理后台,启用/禁用用户时会清空用户表的bug,受影响版本5.2.3/5.2.2/5.2. ...

  2. NutzWk 5.2.0 重磅发布,Java 微服务分布式开发框架

    NutzWk 5.2.0 更新内容: 运维中心重磅功能完成,可在线上传jar包.编辑配置文件.关闭实例进程.启动新实例进程.动态修改日志等级.查看服务器资源占用情况等,支持分布式部署: 文件上传由本地 ...

  3. Java微服务_医疗管理项目_基于若依快速开发框架

    一.项目简介 项目简介:尚医疗是专门为各大医院.门]诊提供的一款医疗管理平台.系统包含:系统 管理.药品进销存管理.看病就诊.收费管理.检查管理.数据统计等核心模块.通过尚医 疗系统可以快速方便的管理 ...

  4. 最热门的13个Java微服务框架

    本文,我们将和大家分享13个可靠的Java微服务架构 1.Spring Boot Java构建Spring应用程序已经有很长一段时间了,Spring Boot是Spring的一个特定版本,它通过对配置 ...

  5. Java微服务:蛋糕是骗人的,但您不能忽略它

    构建微服务实际上意味着什么? 通过微服务框架的眼光回答 忽略微服务的趋势已变得不可能. 有些人会说这只是另一个难以忍受的流行语,而另一些人会背诵打破巨石的优势或采取逆势方法并关注负面因素. 在本文中, ...

  6. Java微服务篇5——Docker

    Java微服务篇5--Docker 1.虚拟化技术 虚拟化技术是一种计算机资源管理技术,是将计算机的各种实体资源,如服务器.网络.内存及存储 等,予以抽象.转换后呈现出来.虚拟化技术打破了计算机实体结 ...

  7. Java微服务篇2——SpringCloud

    Java微服务篇2--SpringCloud 1.微服务架构 1.1.单体应用架构 的⽤户量.数据量规模都⽐较⼩,项目所有的功能模块都放在一个工程中编码. 编译.打包并且部署在一个Tomcat容器中的 ...

  8. Java微服务篇1——SpringBoot

    Java微服务篇1--SpringBoot 1.什么是springboot 1.1.Spring出现的问题 Spring是Java企业版(Java Enterprise Edition,JEE,也称J ...

  9. Java微服务:这个画饼是个谎言,但你却不能忽视它

    本文讲的是Java微服务:这个画饼是个谎言,但你却不能忽视它[编者的话]本文深入介绍了Java的微服务开发,包括其定义和一些可选方案,如Spring Boot.Dropwizard及其他开源项目. 微 ...

最新文章

  1. Xcode 9 快速跳转到定义新姿势(Jump to Definition)
  2. 【原创译文】Jive Circle案例学习:以用户为中心的设计
  3. ASP.NET根路径的获取和将Web站点下的绝对路径转换为虚拟路径的两种方案
  4. SpringMVC架构---SpringMVC学习笔记(一)
  5. mysql监控sql_关于对mysql语句进行监控的方法详解
  6. VSCode工具常用命令总结
  7. linux xenserver教程,Linux虚拟化之XenServer的安装与配置管理
  8. 代码描述10911 - Forming Quiz Teams
  9. TCP粘包问题的解决方案01——自定义包体
  10. MySQL 服务的启动与停止
  11. uvalive 3126 Taxi Cab Scheme
  12. php 5.2 spl_autoload_register,PHP 中的__autoload() 与spl_autoload_register()函数
  13. 【Gym-102606 H】Heat Pipes【奇环染色、bfs 生成树】
  14. linux 学习笔记(基础)
  15. 设置MyEclipse2015黑色主题背景及删除主题
  16. 乐鑫Esp32-S2学习之旅② ESP32-S2 以 I2C 驱动 SHT20 获取温湿度数据,代码开源!
  17. oeasy教您玩转vim - 38 - # 配合移动
  18. sox处理mp3_sox 转码 amr转MP3
  19. sockjs-node报错
  20. 令人愉快的 Nuxt3 教程 (二): 快速轻松地搭建博客

热门文章

  1. weblogic的集群与配置--架构师第九天
  2. 几本OpenCV的参考书籍
  3. SimpleITK读取医学影像文件
  4. 如何将网页变成桌面屏保
  5. 徒步新纪录--从植物园到北理
  6. 计算机主板维修高手,计算机电路基础与维修高手
  7. 如何在rhel4上禁用不需要的相关服务
  8. 采样模型外表面点云之曲线救国方法
  9. EPLAN 设备接线图模板制作
  10. 20200428 线程安全(上)--彻底搞懂volatile关键字