smart-http is aProgrammable HTTP Application Microkernel. It is currently one of the few Http servers on the market that strictly abides by the RFC2616 specification and takes into account excellent performance.

smart-http is completely built on the self-developed communication framework smart-socket, maintaining its pure localized lineage. The target of the project positioning is nginx, and high performance and lightweight are the goals it pursues and persists in.

Strictly speaking, smart-http is not a framework, it is more like a tool library. Based on it, developers can package application frameworks or solutions that fit specific scenarios.

module introduction

moduleillustrateamount of code
smart-http-commonBasic common modules, including enumeration, logging, tool classes2300+
smart-http-clientHTTP Client Codec and Responsive Programming Design1200+
smart-http-serverCodec and application layer interface design of HTTP Server and WebSocket2600+
smart-http-restfulSimple version of MVC module based on smart-http-server (experimental)380+
smart-http-testSingle test module1200+

2. Version update

Maven


<dependency>
    <groupId>org.smartboot.http</groupId>
    <artifactId>smart-http-server</artifactId>
    <version>1.1.20</version>
</dependency>

This update:

  1. smart-socket upgraded to 1.6.1.

  2. HttpRouteHandler supports custom default handler.

  3. New features of the restful module:

3. Get started quickly

3.1 HTTP server


public class SimpleSmartHttp {
    public static void main(String[] args) {
        HttpBootstrap bootstrap = new HttpBootstrap();
        bootstrap.httpHandler(new HttpServerHandler() {
            @Override
            public void handle(HttpRequest request, HttpResponse response) throws IOException {
                response.write("hello smart-http<br/>".getBytes());
            }
        }).setPort(8080).start();
    }
}

3.2 WebSocket server


public class WebSocketDemo {
    public static void main(String[] args) {
        //1. 实例化路由Handle
        WebSocketRouteHandler routeHandle = new WebSocketRouteHandler();

        //2. 指定路由规则以及请求的处理实现
        routeHandle.route("/"new WebSocketDefaultHandler() {
            @Override
            public void handleTextMessage(WebSocketRequest request, WebSocketResponse response, String data) {
                response.sendTextMessage("接受到客户端消息:" + data);
            }
        });

        // 3. 启动服务
        HttpBootstrap bootstrap = new HttpBootstrap();
        bootstrap.webSocketHandler(routeHandle);
        bootstrap.start();
    }
}

3.3 Http client


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::printStackTrace)
                .send();
    }
}

3.4 Restful


<dependency>
    <groupId>org.smartboot.http</groupId>
    <artifactId>smart-http-restful</artifactId>
    <version>${smarthttp.version}</version>
</dependency>

@Controller
public class RestfulDemo {

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String helloworld() {
        return "hello world";
    }

    public static void main(String[] args) throws Exception {
        RestfulBootstrap bootstrap = RestfulBootstrap.getInstance().controller(RestfulDemo.class);
        bootstrap.bootstrap().setPort(8080).start();
    }
}

The smartboot open source organization is a low-key organization that is easily mistaken for “reinventing the wheel”.had won 2020 OSC China Open Source Project “Excellent Gitee Organization”honor.

Star projects within the organization include:

  • smart-socket
    It took 5 years to refine more than 2,000 lines of code, and easily realize the AIO communication framework with millions of long connections.

  • smart-http
    HTTP/1.1 web service implemented based on smart-socket.

  • smart-servlet
    Servlet 3.1 container service implemented based on smart-http.

  • smart-broker
    MQTT 3.1.1/5.0 Broker service implemented based on smart-socket.

  • smart-flow
    A lightweight business orchestration framework with observability.

Organization address: https://smartboot.tech/
Code repository: https://gitee.com/smartboot

#smarthttp #v1120 #release #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *