smart-http 是一款可编程的 Http 应用微内核,方便用户根据自身需求进行 Server 或 Client 的应用开发。
感兴趣的朋友请记得 Star一下该项目,并且非常欢迎有能力的朋友贡献你的想法和代码。
<dependency>
<groupId>io.github.smartboot.http</groupId>
<artifactId>smart-http-server</artifactId>
<version>2.5</version>
</dependency>
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();
}
}
http://localhost:8080/,亦或采用websocket请求ws://127.0.0.1:8080/<dependency>
<groupId>io.github.smartboot.http</groupId>
<artifactId>smart-http-client</artifactId>
<version>2.5</version>
</dependency>
public class HttpGetDemo {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient("www.baidu.com", 80);
httpClient.get("/").header().keepalive(false).done()
.onSuccess(response -> System.out.println(response.body()))
.onFailure(Throwable::printStackTrace)
.done();
}
}