跳至主要內容
Windward

Windward

轻量级Web框架

快速上手 →项目简介

简洁至上👀

只需要函数,无注解,无预定义配置文件

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();

300并发连接

Hello World! 应用五百万请求

系统Ubuntu 22.04

32G内存以及Intel i7-10070处理器