1 Star 0 Fork 110

张天笑 / smart-http

forked from smartboot / smart-http 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 2.61 KB
一键复制 编辑 原始数据 按行查看 历史
三刀 提交于 2023-01-27 19:57 . 正式版1.1.20

smart-http

smart-http 是一款可编程的 Http 应用微内核,方便用户根据自身需求进行 Server 或 Client 的应用开发。

感兴趣的朋友请记得 Star一下该项目,并且非常欢迎有能力的朋友贡献你的想法和代码。

功能列表

  1. 支持GET、POST的 HTTP 请求。
  2. 提供了 URL 路由组件,可以快速搭建一套静态服务器。
  3. 支持部分 RFC2612 规范,后续会逐渐完善。
  4. 支持 Https 协议,由 smart-socket 为其赋能。
  5. 具备文件上传的能力。
  6. 支持 websocket、Cookie
  7. 支持 Server、Client 开发

快速体验

服务端开发

  1. 在您的Maven工程中引入smart-http依赖。
    <dependency>
        <groupId>org.smartboot.http</groupId>
        <artifactId>smart-http-server</artifactId>
        <version>1.1.20</version>
    </dependency>
  2. 拷贝以下代码并启动。
    public class SimpleSmartHttp {
        public static void main(String[] args) {
            HttpBootstrap bootstrap = new HttpBootstrap();
            // 普通http请求
            bootstrap.pipeline().next(new HttpServerHandle() {
                @Override
                public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
                    response.write("hello world<br/>".getBytes());
                }
            });
            // websocket请求
            bootstrap.wsPipeline().next(new WebSocketDefaultHandle() {
                @Override
                public void handleTextMessage(WebSocketRequest request, WebSocketResponse response, String data) {
                    response.sendTextMessage("Hello World");
                }
            });
            bootstrap.setPort(8080).start();
        }
    }
  3. 浏览器访问:http://localhost:8080/,亦或采用websocket请求ws://127.0.0.1:8080/

客户端开发

  1. 在您的Maven工程中引入smart-http依赖。
    <dependency>
        <groupId>org.smartboot.http</groupId>
        <artifactId>smart-http-client</artifactId>
        <version>1.1.20</version>
    </dependency>
  2. 拷贝以下代码并启动。
    public class HttpGetDemo {
        public static void main(String[] args) {
            HttpClient httpClient = new HttpClient("www.baidu.com", 80);
            httpClient.connect();
            httpClient.get("/")
                    .onSuccess(response -> {
                        System.out.println(response.body());
                    })
                    .onFailure(throwable -> throwable.printStackTrace())
                    .send();
        }
    }
Java
1
https://gitee.com/zhangtianxiao/smart-http.git
git@gitee.com:zhangtianxiao/smart-http.git
zhangtianxiao
smart-http
smart-http
master

搜索帮助