Magician Http
1.0.0
Magician是一个基于Netty的小型HTTP服务包,可以非常轻松地启动http服务,并且还支持WebSocket,使用带注释的配置Handler。
如果你想用netty开发一个http服务但又觉得麻烦,那么Magician可能会帮助你。
此外,我们还提供了许多其他组件,这些组件组成了一个非常适合您进行区块链和 Web 开发的工具包。
JDK8+
https://magician-io.com
< dependency >
< groupId >com.github.yuyenews</ groupId >
< artifactId >Magician</ artifactId >
< version >2.0.7</ version >
</ dependency >
<!-- This is the logging package, you must have it or the console will not see anything, any logging package that can bridge with slf4j is supported -->
< dependency >
< groupId >org.slf4j</ groupId >
< artifactId >slf4j-jdk14</ artifactId >
< version >1.7.12</ version >
</ dependency >
创建处理程序
@ HttpHandler ( path = "/" )
public class DemoHandler implements HttpBaseHandler {
@ Override
public void request ( MagicianRequest magicianRequest , MagicianResponse response ) {
// response data
magicianRequest . getResponse ()
. sendJson ( 200 , "{'status':'ok'}" );
}
}
启动http服务
Magician . createHttp ()
. scan ( "handler所在的包名" )
. bind ( 8080 );
@ WebSocketHandler ( path = "/websocket" )
public class DemoSocketHandler implements WebSocketBaseHandler {
@ Override
public void onOpen ( WebSocketSession webSocketSession ) {
}
@ Override
public void onClose ( WebSocketSession webSocketSession ) {
}
@ Override
public void onMessage ( WebSocketSession webSocketSession , byte [] message ) {
}
}