Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/JMagician/Magician-Http

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.
https://github.com/JMagician/Magician-Http

framework http java magician network nio tcp udp websocket

Last synced: about 5 hours ago
JSON representation

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.

Awesome Lists containing this project

README

        


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.

In addition, we provide many other components that make up a toolkit that will work well for you in blockchain and web development.

## Running environment

JDK8+

## Documentation

[https://magician-io.com](https://magician-io.com)

## Example

### Importing dependencies
```xml

com.github.yuyenews
Magician
2.0.7

org.slf4j
slf4j-jdk14
1.7.12

```

### Creating an http service

Create a Handler

```java
@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

```java
Magician.createHttp()
.scan("handler所在的包名")
.bind(8080);
```

### Creating WebSocket

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

}
}
```