简洁至上👀
只需要函数,无注解,无预定义配置文件
Netty驱动💪
享受Netty的速度
轻量🏂
接口即函数
快🚀🚀🚀
相比许多其它框架更快
🛠 安装
重要
JDK 最低要求 8
添加 Windward 依赖
添加 JSON 解析
🚀 运行
Windward.setup()
// 注册路由组
.group("/v1")
.get(
"/hello-world",
simpleWindwardContext -> {
simpleWindwardContext.writeString("Hello World!");
})
// 注册动态路由
.get(
"/user/{id}",
simpleWindwardContext -> {
Object o = simpleWindwardContext.getPathVariables().get("id");
simpleWindwardContext.writeString(String.valueOf(o));
})
.end()
// 注册webSocket
.ws(
"/ws",
webSocketWindwardContext -> {
if (!webSocketWindwardContext.isUpgradedContext()) {
webSocketWindwardContext.writeString("Unsupported protocol");
}
switch (webSocketWindwardContext.getWebSocketEvent()) {
case ON_CONNECT:
webSocketWindwardContext.writeString("Hello World!");
break;
case ON_MESSAGE:
Object webSocketData =
webSocketWindwardContext.getWebSocketData();
webSocketWindwardContext.writeString("Oh?");
break;
default:
}
})
.then()
// 注册静态资源托管规则
.resource("/**.js", "/**.css", "/**.jpeg", "/**.png")
.run();