Giter Club home page Giter Club logo

bay's Introduction

Bay

一个非Servlet规范的JavaWeb框架,包括一个基于Netty的高性能服务器.

##介绍 这是一个基于Netty实现的非Servlet规范的Web服务器,由于底层设计经验不足,所以实际上是完成了对Servlet对外接口的一层包装.此框架与Servlet的相同之处大概就这些.就Servlet注册路由的繁琐,本框架尽量简化了这部分体验,详情请参见用法部分.另外本框架支持session,但提供了两种配置方案:1.内存存储.适合小应用,在单机环境部署.2.Redis存储.可以实现简单的横向扩展,适合大型应用.已支持velocity模板引擎,可渲染页面. 此框架正在完善之中.希望有兴趣的朋友可以联系我,一起完善这个框架.

##用法 ###1.Start

import static com.bay1ts.bay.core.Bay.*;

public class HelloWorld {
    public static void main(String[] args) {
        //支持静态文件
        staticResources("/static");


        //支持RESTful路由,可使用java8 lambda表达式简化编码
        get("/hello", (req, resp) -> {
                    return "World";
                }
        );


        //支持基于命名空间的路由
        NSRoute(
                newNameSpace("/start",

                        //支持controller
                        NSGet("/a", Controller.serveA),

                        NSPost("/b", (req, resp) -> {

                                    //支持 类似SpringMVC的 @requestbody 方式
                                    Pojo pojo = req.requestBody(Pojo.class);
                                    if (pojo == null) {

                                        //停止处理,自定义response
                                        halt(500, "something wrong");
                                    }

                                    //内置Gson,可返回
                                    return pojo;
                                },

                                //支持命名空间嵌套
                                newNameSpace("/c",

                                        //拦截器(/start/c/d/abc   等),request预处理
                                        NSBefore("/*", (req, resp) -> {

                                            //可用作验证授权
                                            return null;
                                        }),

                                        //简单数据绑定
                                        NSGet("/d/:name", (req, resp) -> {
                                                    return req.params(":name");
                                                }
                                        )
                                )
                        )
                )
        );
        //启动服务器.需要写在最后 默认端口5677
        listenAndStart();
    }
}

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.