# smart-http **Repository Path**: javajianghu/smart-http ## Basic Information - **Project Name**: smart-http - **Description**: 基于smart-socket实现的轻量级http服务器 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: https://smartboot.tech/smart-http/ - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 123 - **Created**: 2023-02-01 - **Last Updated**: 2023-02-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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依赖。 ```xml org.smartboot.http smart-http-server 1.1.20 ``` 2. 拷贝以下代码并启动。 ```java 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
".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依赖。 ```xml org.smartboot.http smart-http-client 1.1.20 ``` 2. 拷贝以下代码并启动。 ```java 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(); } } ```