Skip to content

Magician-Route is the official web component of Magician, which was developed from Magician-Web, mainly by removing the reflection inside, sacrificing a bit of ease of use and putting the focus on performance.

License

Notifications You must be signed in to change notification settings

JMagician/Magician-Route

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magician-Route is the official web component of Magician, which was developed from Magician-Web, mainly by removing the reflection inside, sacrificing a bit of ease of use and putting the focus on performance.

Documentation

https://magician-io.com

Example

Importing dependencies

<!-- This is the jar package build by this project -->
<dependency>
    <groupId>com.github.yuyenews</groupId>
    <artifactId>Magician-Route</artifactId>
    <version>1.0.0</version>
</dependency>

<!-- This is Magician -->
<dependency>
    <groupId>com.github.yuyenews</groupId>
    <artifactId>Magician</artifactId>
    <version>2.0.7</version>
</dependency>

<!-- This is the log package, which supports any package that can be bridged with slf4j -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>1.7.12</version>
</dependency>

Creating core handlers

@HttpHandler(path="/")
public class DemoHandler implements HttpBaseHandler {

    @Override
    public void request(MagicianRequest magicianRequest, MagicianResponse response) {
        try{
            MagicianRoute.request(magicianRequest);
        } catch (Exception e){
        }
    }
}

Creating Route

@Route
public class DemoRoute implements MagicianInitRoute {

    @Override
    public void initRoute(MagicianRouteCreate routeCreate) {
        routeCreate.get("/demo/getForm", request -> {
            DemoVO demoVO = ConversionUtil.conversionAndVerification(request, DemoVO.class);
            System.out.println(request.getParam("name") + "---" + demoVO.getName());
            return "{\"msg\":\"hello login\"}";
        });

        routeCreate.post("/demo/json", request -> {
            DemoVO demoVO = ConversionUtil.conversionAndVerification(request, DemoVO.class);
            System.out.println(request.getJsonParam() + "---" + demoVO.getName());
            return "{\"msg\":\"hello json\"}";
        });
    }
}

Start HTTP service

Magician.createHttp()
                .scan("Packages to be scanned")
                .bind(8080);

About

Magician-Route is the official web component of Magician, which was developed from Magician-Web, mainly by removing the reflection inside, sacrificing a bit of ease of use and putting the focus on performance.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages