Giter Club home page Giter Club logo

bendoroll's Introduction

Bendoroll - A lightweight java-web framework

A lightweight java-web framework,reference from simplify_mvc and javalin, just use for learning exchange ,I trust that you wont to use for production environment hah hah

一款轻量级java-web框架,参考自SpringMVC与Javalin,仅作学习交流使用

Updated Continually

TODO:

  • Lifecycle AOP
  • file response support
  • any more...

Features:

  • 😎 Simplify
  • 😍 OOTB
  • 🚀 Get started quickly
  • 📕 Can be used for learning
  • ✌️ Less code amount
  • 🦾 Also no @Annotation
  • ❤️ Also no reflection
  • 😀 Just function

You just need call some functions , so easy

QuickStart

complie the source code to generate *.jar file

import this by maven , gradle, or move it to your lib-dir

Start Programming

This example to build and run a simple web application

public class Main {
    public static void main(String[] args) {
        Bendoroll app = Bendoroll.create();
        app.get("/example",ctx->{
            ctx.html("Hello World!");
        });
        app.start();
    }
}

Examples

There exist some examples about how to use the framework

Build some restful api

public class Main {
    public static void main(String[] args) {
        Bendoroll app = Bendoroll.create(8080);
        app.get("/user", ctx -> {
            ctx.ok.put(new User("ZJamss","Dont have delusion"));
        });
        app.post("/user", ctx -> {
            final User user = ctx.body(User.class);
            //....  do something in Dao 
            ctx.ok();
        });
        app.put("/user", ctx -> {
            final User user = ctx.body(User.class);
            //.... do something in Dao 
            ctx.ok();
        });
        app.delete("/user", ctx -> {
            final User user = ctx.body(User.class);
            //....  do something in Dao 
            ctx.ok();
        });
        app.start();
    }

    static class User{}
}

Build an ExceptionHandler to handle some exceptions in the api

public class Main {
    public static void main(String[] args) {
        Bendoroll app = Bendoroll.create(8080);

        app.post("/user", ctx -> {
            final User user = ctx.body(User.class);
            //....  do something in Dao
            if(user == null){
                throw new RuntimeException("cant resolve the request body");
            }
            ctx.ok();
        });
        app.exception(RuntimeException.class,((e, ctx) -> {
            //do something to process the exception, such as log...
            ctx.error(400);
        }));
        app.start();
    }
    
    static class User{}
}

Build some AOP Handlers for a api

public class Main {
    public static void main(String[] args) {
        Bendoroll app = Bendoroll.create();
        app.get("/", ctx -> {
            ctx.ok().put("person", new Person(ctx.param("name"), 19, "Dont have delusion"));
        });
        app.aspect(Lifecycle.AROUND, "/", ctx -> {
            ctx.ok().put("around","around");
            return true;
        });
        app.aspect(Lifecycle.BEFORE, "/", ctx -> {
            ctx.ok().put("before","before");
            if(ctx.param("name") == null){
                ctx.error(400,"别来沾边");
            }
            return false;
        });
        app.aspect(Lifecycle.AFTER, "/", ctx -> {
            ctx.ok().put("after","after");
            return true;
        });
        app.aspect(Lifecycle.EXCEPTION, "/", ctx -> {
            ctx.ok().put("exception","exception");
            return true;
        });
        app.exception(BaseException.class, (e, ctx) -> {
            ctx.html("error");
        });
        app.start();
    }

    static class Person {}

}

File access

public class Main {

    public static void main(String[] args) {
        Bendoroll app = Bendorollmo
                .create()
                .fileAccess(true) //Default Off
                .fileFolderName("static"); //Default `resources/public`
        app.get("/index",ctx -> {
            ctx.file("index.html");
        });
        //or access host:port/filename to view it online
        //for example localhost:8080/index.html
        app.start();
    }
}

bendoroll's People

Contributors

zjamss avatar

Stargazers

BeanMak1r avatar Ki June avatar  avatar Devmc 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.