moe java api server

moeserver

Лицензия

Лицензия

Группа

Группа

com.github.timeloveboy
Идентификатор

Идентификатор

moeserver
Последняя версия

Последняя версия

0.1.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

moe java api server
moeserver
Ссылка на сайт

Ссылка на сайт

https://github.com/timeloveboy/moeserver
Система контроля версий

Система контроля версий

https://github.com/timeloveboy/moeserver

Скачать moeserver

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.timeloveboy/moeserver/ -->
<dependency>
    <groupId>com.github.timeloveboy</groupId>
    <artifactId>moeserver</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.timeloveboy/moeserver/
implementation 'com.github.timeloveboy:moeserver:0.1.1'
// https://jarcasting.com/artifacts/com.github.timeloveboy/moeserver/
implementation ("com.github.timeloveboy:moeserver:0.1.1")
'com.github.timeloveboy:moeserver:jar:0.1.1'
<dependency org="com.github.timeloveboy" name="moeserver" rev="0.1.1">
  <artifact name="moeserver" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.timeloveboy', module='moeserver', version='0.1.1')
)
libraryDependencies += "com.github.timeloveboy" % "moeserver" % "0.1.1"
[com.github.timeloveboy/moeserver "0.1.1"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
io.netty : netty-all jar 4.0.4.Final
org.eclipse.jetty : jetty-server jar 9.2.10.v20150310
com.github.timeloveboy : utils jar 0.1

Модули Проекта

Данный проект не имеет модулей.

moeserver


    ______        _____
    |_    \      /    _|
      | |\ \    / /| |          _____       _____
      | | \ \__/ / | |         /  _  \     / ____\
     _| |_ \____/ _| |_       |  |_|  |   | ____  |
    |_____|      |_____|       \_____/     \_____|

Sun Oct 23 22:31:03 CST 2016 Running at:0.0.0.0/0.0.0.0:8090

萌萌哒的java restful api框架

  • 0.0.1 采用了sun.HttpServer线程模型
  • 0.0.2 采用了netty4引擎和jetty引擎
  • 0.1.0 改进了部分方法,增加了utils库
  • 0.1.1 移除了jetty

using maven

  • 0.0.1 采用了sun.HttpServer线程模型
<dependency>
  <groupId>com.github.timeloveboy</groupId>
  <artifactId>moeserver</artifactId>
  <version>0.1.0</version>
</dependency>
  • 0.0.2 添加了netty4和jetty引擎
<dependency>
  <groupId>com.github.timeloveboy</groupId>
  <artifactId>moeserver</artifactId>
  <version>0.0.2</version>
</dependency>
  • 0.1.0 添加了staticFileHandler,帮助web站点处理静态文件
<dependency>
  <groupId>com.github.timeloveboy</groupId>
  <artifactId>moeserver</artifactId>
  <version>0.1.0</version>
</dependency>

使用说明

  • 1.指定您的modulepackage路径和端口号
  • 2.在modulepackage中,每个类均继承自 extends DefaultHandle
public class Buy extends DefaultHandle {
    @Override
    public void GET(IHttpRequest req, IHttpResponse resp) throws IOException {
        resp.write("get");
    }
}
public class app {
    public static void main(String[] args) throws Exception {
       Server s = Server.getInstance();

        s.RegisterDriver(new nettyServer().setBufMax(1024 * 1));
        //s.RegisterDriver(new sunServer());
        //s.RegisterDriver(new jettyServer());
        s.RegisterModulePath("webdemo.routers").Static("/static", "/CODE/github.com/timeloveboy/moeserver").SetPort(8098);
        s.Run();
    }
}

现在,请访问http://localhost:8090/Buy

函数列表

Server

Server s = Server.getInstance();
s.Static("/static", "/CODE/github.com/timeloveboy/moeserver")
s.RegisterDriver(new nettyServer());
s.RegisterDriver(new sunServer());
s.RegisterDriver(new jettyServer());
s.RegisterModulePath("webdemo.routers").SetPort(8090);
s.Run();

Handle

请覆盖DefauldHandle类的以下方法

  • GET
  • POST
  • PUT
  • HEAD
  • DELETE

moeserver与restful风格的api设计规范可以完美搭配。 您可以:

  • 在get中执行数据的select操作
  • 在post中执行insert操作
  • 在put中执行update操作
  • 在delete中执行delete操作。

Request

   public InetSocketAddress getRemoteAddress()
   
   public InputStream getBody()
   
   public String getRequestMethod() 

   public URI getUrl() 

   public Map getHeaders()

   public Map<String, String> getCookies()

Response

public IHttpResponse code(Integer responsecode) 

public IHttpResponse header(String key, String value)

public IHttpResponse setcookie(String key, String value) 

public void write(String data) 

public void write(byte[] data) 

public void close() 

不服跑个分

机器

ubuntu 16.04
15.7 GiB
Intel® Xeon(R) CPU X5650 @ 2.67GHz × 12
64 位

c=10 n=10000

localhost:~ timeloveboy$ ab -n 10000 -c 10  http://localhost:8090/I
  • sun.线程模式 12688.99 [#/sec] (mean)

  • netty事件模式 19350.82 [#/sec] (mean)

  • jetty 16883.56 [#/sec] (mean)

  • golang 19955.14 [#/sec] (mean)

c=100 n=100000

localhost:~ timeloveboy$ ab -n 100000 -c 100  http://localhost:8090/I
  • sun.线程模式 10409.97 [#/sec] (mean)

  • netty事件模式 18835.13 [#/sec] (mean)

  • jetty 18025.67 [#/sec] (mean)

  • golang 20826.30 [#/sec] (mean)

Версии библиотеки

Версия
0.1.1
0.1.0
0.0.2
0.0.1