/sky

HTTP,WebSocket ... with Netty

Primary LanguageJavaApache License 2.0Apache-2.0

Sky | Netty Based Transport Tool Kit.

🚀 Use sky you can quickly create an http service or websocket service

Features

  • Http Server
  • Websocket Server
  • Spring boot starter in development (已经基本可用)
  • more...

Showcase

<dependency>
  <groupId>io.github.fzdwx</groupId>
  <artifactId>sky-http-springboot-starter</artifactId>
  <version>0.11.3.2</version>
</dependency>
import http.HttpServerRequest;
import sky.starter.UseSkyWebServer;
        
@SpringBootApplication
@RestController
@UseSkyWebServer
public class BurstServerApplication {

    public static void main(String[] args) {
        final ConfigurableApplicationContext run = SpringApplication.run(BurstServerApplication.class);
    }

    // normal request
    @GetMapping("hello")
    public String hello(@RequestParam String name) {
        return "Hello " + name;
    }

    // Upgrade to websocket
    @GetMapping("connect")
    public void connect(@RequestParam String name, HttpServerRequest request) {
        // Can be authenticated here
        // There is no websocket connection established here, the consumption is small,
        // and it is adapted to spring's annotations for taking parameters.
        
        request.upgradeToWebSocket(ws->{
            // When a connection is successfully established with the client
            ws.mountOpen(h -> {
                ws.send("Hello " + name);
            });

            // Process the binary data sent by the client
            ws.mountBinary(b -> {
                
            });

            // Process the text data sent by the client
            ws.mountText(s -> {

            });

            // For example, read idle or write idle events
            ws.mountEvent(e -> {

            });
            
            
            // ...
        });
    }
}