smartboot 开源组织 smartboot 开源组织
首页
  • smart-socket
  • smart-http
  • smart-servlet
  • smart-mqtt
  • smart-license
  • feat
❤️开源捐赠
💰付费服务
🏠加入社区
  • Gitee (opens new window)
  • Github (opens new window)
首页
  • smart-socket
  • smart-http
  • smart-servlet
  • smart-mqtt
  • smart-license
  • feat
❤️开源捐赠
💰付费服务
🏠加入社区
  • Gitee (opens new window)
  • Github (opens new window)
  • 指南

    • 快速上手
      • 服务端
        • 示例程序
      • 客户端
        • 示例程序
    • 服务配置
    • 静态资源服务
    • 请求路由
    • 安全性设计
    • WebSocket
    • 关于 smart-http-restful
  • smart-http
  • 指南
三刀
2022-10-27
目录

快速上手

# 服务端

# 示例程序

下面是使用 smart-http 进行服务端开发最简单的一段代码。

public class SimpleSmartHttp {
    public static void main(String[] args) {
        HttpBootstrap bootstrap = new HttpBootstrap();
        bootstrap.configuration().debug(true);
        bootstrap.httpHandler(new HttpServerHandler() {
            @Override
            public void handle(HttpRequest request, HttpResponse response) throws IOException {
                response.write("hello smart-http<br/>".getBytes());
            }
        }).setPort(8080).start();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12

# 客户端

# 示例程序

下面是使用 smart-http 进行客户端开发最简单的一段代码。

public class HttpGetDemo {
    public static void main(String[] args) {
        HttpClient httpClient = new HttpClient("www.baidu.com", 80);
        httpClient.get("/")
                .onSuccess(response -> System.out.println(response.body()))
                .onFailure(Throwable::printStackTrace)
                .done();
    }
}
1
2
3
4
5
6
7
8
9

我们推荐采用响应式编程范式进行客户端开发,比如注册 onSuccess、onFailure 等回调事件。 当然,调用 done 方法返回的 Future 对象依旧能满足您对于同步调用的需求。

服务配置

服务配置→

Theme by Vdoing | Copyright © 2017-2025 三刀
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式