Menu

Tree [984e8a] master /
 History

HTTPS access


File Date Author Commit
 .github 2021-10-31 yuyenews yuyenews [17d69b] 修复手动配置TCPServerConfig时,magicianHandlerMap与webS...
 src 2022-01-17 yuyenews yuyenews [984e8a] 修复表单提交时的一个细节问题
 .gitignore 2021-04-10 yuyenews yuyenews [31b4d7] 首次提交
 BACKERS.md 2021-06-25 yuyenews yuyenews [727653] 添加支持者榜单
 LICENSE 2021-04-12 yuyenews yuyenews [15e460] 首次提交
 README.md 2022-01-17 yuyenews yuyenews [984e8a] 修复表单提交时的一个细节问题
 pom.xml 2022-01-17 yuyenews yuyenews [984e8a] 修复表单提交时的一个细节问题

Read Me

Magician ·

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.

Running environment

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

Documentation

https://magician-io.com

Example

Importing dependencies

<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>

Creating an http service

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);

Creating WebSocket

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

    }
}

More components

These components can be used to develop web projects easily

Magician-Web |
Magician-JDBC

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.