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 ) {
}
}