File | Date | Author | Commit |
---|---|---|---|
.github | 2021-10-31 |
![]() |
[17d69b] 修复手动配置TCPServerConfig时,magicianHandlerMap与webS... |
src | 2022-01-17 |
![]() |
[984e8a] 修复表单提交时的一个细节问题 |
.gitignore | 2021-04-10 |
![]() |
[31b4d7] 首次提交 |
BACKERS.md | 2021-06-25 |
![]() |
[727653] 添加支持者榜单 |
LICENSE | 2021-04-12 |
![]() |
[15e460] 首次提交 |
README.md | 2022-01-17 |
![]() |
[984e8a] 修复表单提交时的一个细节问题 |
pom.xml | 2022-01-17 |
![]() |
[984e8a] 修复表单提交时的一个细节问题 |
Magician is a small HTTP service package based on Netty that makes it very easy to start an http service, and also supports WebSocket, using annotated configuration Handler.
If you want to develop an http service with netty but find it cumbersome, then Magician may help you.
JDK11+
The Jar package for the maven central library supports at least JDK11, but the source code can support at least jdk8, if you need to run on 8, you can download the latest tag and compile it yourself
<dependency>
<groupId>com.github.yuyenews</groupId>
<artifactId>Magician</artifactId>
<version>2.0.2</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>
Create a Handler
@HttpHandler(path="/")
public class DemoHandler implements HttpBaseHandler {
@Override
public void request(MagicianRequest magicianRequest, MagicianResponse response) {
// response data
magicianRequest.getResponse()
.sendJson(200, "{'status':'ok'}");
}
}
Start the http service
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(String message, WebSocketSession webSocketSession) {
}
}
These components can be used to develop web projects easily